admin 管理员组

文章数量: 1086019

Angular项目开发,在定义一个TypeScript类的时候VSCode报错,提示为:

Property 'name' has no initializer and is not definitely assigned in the constructor

说是属性没有在构造器里面初始化。但是每个类每个属性都要初始化的话太麻烦了。

TypeScript官方文档中查到了方法,可以关闭这个检查:

https://www.typescriptlang/docs/handbook/release-notes/typescript-2-7.html

方法:tsconfig.json > compilerOptions, 增加一项:"strictPropertyInitialization":false, 这样就能不去做属性初始化了:

问题解决。

 

本文标签: 报错 ts Angular property constructor