When trying to access a variable with type indexing in Angular 13, I encountered a TS7053 error. However, in this Stackblitz example, the same code works without any errors.
export class AppComponent {
name = 'Angular ' + VERSION.major;
Prop01 : boolean = false;
Prop02 : boolean = false;
Prop03 : boolean = false;
private setProp(prop: string, value: boolean): void {
this[prop] = value; // this works in the Stackblitz but not in my project
}
}
The only difference is that I'm using version 13 while Stackblitz still uses version 12. I checked my VS Code extensions and noticed that Ts Lint
was deprecated in favor of Es Lint
. I disabled it and restarted VS Code, but this[prop]
still triggers an error that states:
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'MyComponent'. No index signature with a parameter of type 'string' was found on type 'MyComponent'.
I have successfully done this in older Angular versions, so I'm puzzled by why it is not working suddenly. Does anyone have an insight into why this is happening?