'How can use Object.getOwnPropertyNames with this operator TypeScript
class MyClass {
private firstKey: string | null = 'Test';
private secondKey: number | null = 123;
private thirdKey: string[] | null = [ 'first', 'second', 'third' ];
constructor( firstParam: string, secondParam: string[] ) {}
destroy() {
for ( const propertyName of Object.getOwnPropertyNames( this ) ) {
this[ propertyName ] = null;
}
}
}
I got an error on this code this[ propertyName ] and the error message is:
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'MyClass'.
No index signature with a parameter of type 'string' was found on type 'MyClass'.
How can solve this error? Especially that I can't give any type for this operator?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
