Type string trivially inferred from a string literal, remove type annotation (no-inferrable-types)

TypeScript代码:

private goY : string = 'www.baidu.com';

会导致tslint报错:

Type string trivially inferred from a string literal, remove type annotation (no-inferrable-types)。

tslint觉得自己根据右边的"www.baidu.com"判断出requestUrl的类型是string,所以,认为再写string是多此一举。

解决方法:tslint.json添加"ignore-properties"。不推断类的属性(字段)。

 "no-inferrable-types": [
      true,
      "ignore-params",
      "ignore-properties"
    ],

-------------------------------------------------

TypeScript无类型推断配置。

译文:

规则:无推断类型

不允许对初始化为数字,字符串或布尔值的变量或参数进行显式类型声明。

合理

编译器容易推断的显式类型使得代码更加冗长。

标记:

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
}

 

转载于:https://my.oschina.net/u/2381372/blog/1545832

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值