Type string trivially inferred from a string literal, remove type annotation

Angular报错:Type string trivially inferred from a string literal, remove type annotation

stockCode: string = 'IBM';

tslint觉得根据'IBM'判断出stockCode的类型是string,所以再写成string类型是多此一举。

那么怎么去掉这条规则呢?

ctrl+shift+p搜索tslint,选择TSLint:Create a 'tslint.json' file

将:

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

改成:

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

 

你可能感兴趣的:(O-VSCode)