TypeScript代码:json
private goY : string = 'www.baidu.com';
会致使tslint报错:swift
Type string trivially inferred from a string literal, remove type annotation (no-inferrable-types)。函数
tslint以为本身根据右边的"www.baidu.com"判断出requestUrl的类型是string,因此,认为再写string是画蛇添足。spa
解决方法:tslint.json添加"ignore-properties"。不推断类的属性(字段)。code
"no-inferrable-types": [ true, "ignore-params", "ignore-properties" ],
-------------------------------------------------ip
TypeScript无类型推断配置。rem
译文:字符串
不容许对初始化为数字,字符串或布尔值的变量或参数进行显式类型声明。编译器
合理string
编译器容易推断的显式类型使得代码更加冗长。
标记:
TS独有已经固定
能够提供两个参数:
ignore-params
容许为函数参数指定不可推出的类型注释。当与typedef
规则组合时,这能够颇有用。ignore-properties
容许为类属性指定不可推出的类型注释。例子:
"no-inferrable-types": true "no-inferrable-types": [true, "ignore-params"] "no-inferrable-types": [true, "ignore-params", "ignore-properties"]
样板:
{ "type": "array", "items": { "type": "string", "enum": [ "ignore-params", "ignore-properties" ] }, "minLength": 0, "maxLength": 2 }