Where there is no error at this line
if (!t[1]) {
t[1] = [];
}
t[1].push(key);
t is of type Test, which is not directly indexible. But, it has a member, data, which can be indexed. So why there is no error in these lines.
ITestData models a nested object, with integer and string key respectively.
{
1 : {
"hello" : {}
}
2 : { ..
}
Code:
export interface ITestData {
[idx:number] : {[prop:string]:any}
}
export interface ITest {
data:ITestData
}
export class Test implements ITest {
data:ITestData = {};
}
class Greeter {
data:ITestData = {};
private del(t:Test, key:string) {
if (!t[1]) {
t[1] = [];
}
t[1].push(key);
}
}