繁体   English   中英

针对 TypeScript 中函数类型参数的 ESLint 未使用变量规则

[英]ESLint un-used varialbes rule for parameters of function type in TypeScript

我正在将 ESLint 与 TypeScript 一起使用。 当我尝试使用一些必需参数创建函数类型时,ESLint 显示错误eslint: no-unused-vars

type Func = (paramA: number) => void这里,根据 ESLint,paramA 是未使用的变量。

我的.eslintrc.json文件

{
    "env": {
        "browser": true,
        "es6": true
    },
    "extends": [
        "eslint:recommended",
        "plugin:@typescript-eslint/eslint-recommended"
    ],
    "globals": {
        "Atomics": "readonly",
        "SharedArrayBuffer": "readonly"
    },
    "parser": "@typescript-eslint/parser",
    "parserOptions": {
        "ecmaFeatures": {
            "jsx": true
        },
        "ecmaVersion": 2018,
        "sourceType": "module"
    },
    "plugins": [
        "react",
        "@typescript-eslint"
    ],
    "rules": {
    }
}

那么,使用 ESLint 在 TypeScript 中创建函数类型的正确方法是什么?

提前致谢

typescript-eslint文档中所述,从 eslint 禁用规则并从 typescript-eslint 启用。

{
  // note you must disable the base rule as it can report incorrect errors
  "no-unused-vars": "off",
  "@typescript-eslint/no-unused-vars": ["error"]
}

如果我理解正确的话,你要做的是

const func: (paramA: number) => void

定义一个函数类型。

实际上,他们已经在他们的常见问题解答中回答了这个问题

我需要关闭 eslint 的no-unused-vars规则,并打开typescript-eslint规则。

"rules": {
  "no-unused-vars": "off",
  "@typescript-eslint/no-unused-vars": "error"
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM