TypeScript complain “has no initializer and is not definitely assigned in the constructor” about constructors by returning constructed object

后端 未结 4 2206
花落未央
花落未央 2021-02-20 03:19

TypeScript show following error message to this code samples:

class MyClass {
  someField: boolean;
  constructor() {
    return { someField: true };
  }
}
         


        
4条回答
  •  囚心锁ツ
    2021-02-20 04:05

    "angularCompilerOptions": {
        //   ...
        "strictPropertyInitialization": false
        //   ...   }
    

    According to angular latest version, it supports strict typing, so you have to disbale it.

    Make modifications and restart server

提交回复
热议问题