ESLint - TypeScript 类型/接口中函数参数的“no-unused-vars”

Mus*_*ill 13 typescript eslint

Types我目前收到关于or内的函数参数的 eslint 警告Interfaces

执行以下操作:

type Test = {
  fn: (param: string) => void
}
Run Code Online (Sandbox Code Playgroud)

结果出现以下警告:

'param' is defined but never used. Allowed unused args must match /^_/u.
Run Code Online (Sandbox Code Playgroud)

这是我的.eslintrc.json样子:

{
  "root": true,
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "project": "tsconfig.json"
  },
  "env": {
    "node": true
  },
  "plugins": ["@typescript-eslint"],
  "extends": [
    "eslint:recommended",
    "plugin:@typescript-eslint/eslint-recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:prettier/recommended"
  ],
  "rules": {
    "@typescript-eslint/interface-name-prefix": "off",
    "@typescript-eslint/explicit-function-return-type": "off",
    "@typescript-eslint/explicit-module-boundary-types": "off"
  }
}
Run Code Online (Sandbox Code Playgroud)

封装版本:

"eslint": "^7.23.0"
"@typescript-eslint/eslint-plugin": "^4.22.1"
"@typescript-eslint/parser": "^4.22.1"
Run Code Online (Sandbox Code Playgroud)

类似的问题已经在这里这里被问过,但提供的答案似乎并不适合我。

对于可能发生的情况有什么建议吗?

Eld*_*lho 15

我是这样解决的,将这两行放在 eslint 配置文件的规则中。

"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": ["error"]
Run Code Online (Sandbox Code Playgroud)