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
I have another case of this. I want to enforce that whenever a class instance is created, the correct sub class constructor is used. A simplified repro would be the following:
classFoo{constructor(){if(new.target!==Sub)returnnewSub();this.version=1;}publicversion: number;// Error: Property 'version' has no initializer and is not definitely assigned in the constructor.}classSubextendsFoo{}// default constructor has the same issue as any constructor which calls superconsole.log(newFoo().version);// prints 1console.log(newSub().version);// prints 1
As you can see, version is always defined, but TypeScript doesn't think so.
TypeScript Version: 3.2.0-dev.20181004
Code
Expected behavior:
No error.
Actual behavior:
The text was updated successfully, but these errors were encountered: