Answer the question
In order to leave comments, you need to log in
Typescript: why does an error occur when trying to access an element of an object that is described by an interface?
There is a type code
interface Interface {
[id: string]: Interface2;
}
interface Interface2 {
[id: string]: string|boolean;
}
var a:Interface = {
abc: {
a: 'a',
b: 'b',
c: 'c'
},
cde: {
c: 'c',
d: 'd',
e: true
}
};
if (a.cde.e) {
console.log(1);
} else {
console.log(2);
}
if (a['cde']['e']) {
console.log(1);
} else {
console.log(2);
}
Property 'cde' does not exist on type 'Interface'.
Answer the question
In order to leave comments, you need to log in
https://github.com/Microsoft/TypeScript/issues/4345 stigma "By Design"
At least it checks the type.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question