During my code refactoring process, I encountered an unusual behavior from the TypeScript compiler that has left me puzzled.
interface IPoint {
x: number;
y: number;
}
let a: IPoint = { x: 5, y: 10 };
let b = a[0];
console.log(b);
Upon compiling this code, I expected the compiler to generate an error due to attempting to access a non-existent key of a
(at compile-time).
Why doesn't this result in an error? Could there be a TSLint configuration setting that identifies using []
on objects as an error or warning?
Thank you in advance for any insights and best regards.