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

Error on `(interface-name) [typescript/tslint]` rule?

我收到这个 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;

interface-name rule要求所有接口都是大写字母I。这是为了区分接口和 classes(因为接口不是值,但 class 是)。在您的情况下,您可以通过将接口命名为 IProps.

来更正代码

修改你的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
}

您可以尝试在 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"]
  }
}