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, 这样就能不去做属性初始化了:
问题解决。
更多推荐
Angular TS类报错:Property ‘name‘ has no initializer and is not definitely assigned
发布评论