You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// A *self-contained* demonstration of the problem follows...exportclassClassA{publicclean(){for(letpropinthis){if(typeofthis[prop]==="boolean")this[prop]=false;}}}
Expected behavior:
Compiled without error
Actual behavior:
Error Type false is not assignable to type this[keyof this]
The text was updated successfully, but these errors were encountered:
Try adding interface BoolMap { [key: string]: boolean; } and change the initial class declaration to class ClassA implements BoolMap. TypeScript doesn't know that ClassA, or subclasses thereof, could even have any dynamic boolean properties, because it can only infer so much. Alternatively, you could use a temporary reference and cast the stored value to {[key: string]: boolean} & this.
(Oh, and you're iterating the prototype chain with that; might be a good idea to guard that with hasOwnProperty.)
TypeScript Version: 2.1.4
Code
Expected behavior:
Compiled without error
Actual behavior:
Error
Type false is not assignable to type this[keyof this]
The text was updated successfully, but these errors were encountered: