Is it possible to configure the Typescript compiler to identify errors when accessing object properties using square brackets?
I have inherited a codebase where object property access is predominantly done with square brackets (obj['myProp']
instead of obj.myProp
). I need to implement type checking for this scenario. Below is an example of the code, which unfortunately does not throw any compile-time errors. Is there a way to prompt the compiler to recognize that the property 'test' does not exist?
interface IPerson{
name: string
}
let x: IPerson
x = { name: 'John' };
let y = x['test'];