1. 注解以大写字母开头报错
报错信息:
A function with a name starting with an uppercase letter should only be used as a constructor. (new-cap)
解决方法:
加注释 // eslint-disable-next-line new-cap
// eslint-disable-next-line new-cap
@ViewChild...........;
2. 误报
报错信息:
'XXX' is defined but never used. (no-unused-vars)
实际情况是XXX被使用了,这属于误报
解决方法:
加注释,使其忽略下一行校验
方法1:在错误语句后添加注释 // eslint-disable no-unused-vars
方法2:使用/* eslint-disable no-unused-vars */注释
3. any类型报错
报错信息:
Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
解决方法:
比如 把 public total: any 改为 public total: number
把any类型改为对应的具体数据类型,比如:number; string; boolean; object ;
object[] ; number[];;Date
4. json参数判断是否存在某字段使报错
报错信息:
Do not access Object.prototype method 'hasOwnProperty' from target object. (no-prototype-builtins)
治理:
把 json.hasOwnProperty('key')
修改为: Object.prototype.hasOwnProperty.call(json, 'key')