Angular TS类报错:Property ‘name‘ has no initializer and is not definitely assigned in the constructor

编程知识 更新时间:2023-05-01 23:28:13

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

本文发布于:2023-04-24 13:15:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/441299a393b3fa6f8089687caea9cff8.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:报错   TS   Angular   Property   constructor

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 100590文章数
  • 26056阅读数
  • 0评论数