I'm trying to access a variable with type indexing in Angular 13 and am getting a TS7053 error. This stackblitz shows exactly what I'm doing however it works perfectly fine in there with no error.
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 I'm using V13 while stackblitz still uses V12. I looked at my VS Code extensions and saw Ts Lint
was deprecated in favor of Es Lint
so I disabled it and rebooted VS Code but this[prop]
still throws an error that says
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've done this in older versions of Angular so I don't understand what's making it not work all of a sudden, anyone know why this is?