TypeScript报错

一、Property propDD has no initializer and is not definitely assigned in the constructor

1、object类型

 

解决方案  

检测报错代码
@Prop() propDD: object;
修改后
方式一
@Prop({ type: Object, default: {} }) propDD: any;
方式二
@Prop() propDD?: object;


2、array类型

 

解决方案

检测报错代码
@Prop() propF: string[];
@Prop() propG: Array<number>;
修改后
@Prop() propF?: string[];

原文链接:https://blog.csdn.net/Tomoe20/article/details/106210357/

二、any类型警告

(property) DateHelper.prmimaryKey: string
元素隐式具有 "any" 类型,因为类型为 "string" 的表达式不能用于索引类型 "{}"。
在类型 "{}" 上找不到具有类型为 "string" 的参数的索引签名。ts(7053)
速览问题 (Alt+F8) 没有可用的快速修复

我们在项目中的tsconfig.json文件中添加:

 "suppressImplicitAnyIndexErrors":true,


原文链接:https://blog.csdn.net/beLaity/article/details/108527556

如果觉得本文对您有帮助~可以支付宝(左)或微信支持一下:


看到小伙伴打赏时给我写一些鼓励的话,真的非常感动,谢谢你们。


我开了个微信公众号(第三个二维码)用来分享自己的职场英语相关学习经验,感兴趣可以关注,我会不断更新~


微信打赏微信公众号

原文地址:https://www.cnblogs.com/starof/p/14472369.html