`(interface-name)[typescript / tslint]`规则出错?

时间:2017-11-01 08:43:34

标签: tslint

我得到了这个tslint错误,我不明白为什么。界面以大写字母开头。

29 col 11 error| interface name must start with a capitalized I (interface-name) [typescript/tslint]

S> 29 interface Props {
   30   answerQuestion: (answerQuestion: AnswerQuestion) => void;

3 个答案:

答案 0 :(得分:5)

interface-name rule要求所有接口都使用大写字母I。这是为了区分接口和类(因为接口不是值,而是类)。在您的情况下,您可以通过命名界面IProps来更正代码。

答案 1 :(得分:1)

您可以尝试在tslint.json =>

中添加以下代码
{
  "extends": ["tslint:recommended", "tslint-react", "tslint-config-prettier"],
  "linterOptions": {
    "exclude": [
      "config/**/*.js",
      "node_modules/**/*.ts",
      "coverage/lcov-report/*.js"
    ]
  },
  "rules": {
    "interface-name" : [true, "never-prefix"]
  }
}


答案 2 :(得分:0)

修改您的tslint.json

{
  "extends": [
    "tslint:recommended",
    "tslint-react",
    "tslint-config-prettier"
  ],
  "linterOptions": {
    "exclude": [
      "config/**/*.js",
      "node_modules/**/*.ts"
    ]
  },
  "interface-name" : [true, "never-prefix"] // <-- Include this line
}