TypeScript show following error message to this code samples:
class MyClass {
someField: boolean;
constructor() {
return { someField: true };
}
}
It considers {someField: true} as new object and the property someField has not been initialized.What is the purpose of return inside the constructor? You can replace it with this.someField = true
.
Edit: Actually, I debugged for more info, Try adding "strictPropertyInitialization": false to your compiler options and check. But it overrules the type strictness(beautiful feature of TS). But In my opinion, do not do this. For more info.