[英]ESLint un-used varialbes rule for parameters of function type in TypeScript
I'm using ESLint with TypeScript.我正在将 ESLint 与 TypeScript 一起使用。 When I try to create a function type with some required parameters, ESLint shows error
eslint: no-unused-vars
.当我尝试使用一些必需参数创建函数类型时,ESLint 显示错误
eslint: no-unused-vars
。
type Func = (paramA: number) => void
Here, paramA is un-used variable according to ESLint. type Func = (paramA: number) => void
这里,根据 ESLint,paramA 是未使用的变量。
My .eslintrc.json
file我的
.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": {
}
}
So, what is then, the correct way to create a function type in TypeScript with ESLint?那么,使用 ESLint 在 TypeScript 中创建函数类型的正确方法是什么?
Thanks in advance提前致谢
As mentioned in the document of typescript-eslint , disabled the rule from eslint and enable from typescript-eslint.如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"]
}
If I understood you correctly, what you're trying to do is如果我理解正确的话,你要做的是
const func: (paramA: number) => void
to define a function type.定义一个函数类型。
Actually, they have answered to this question in their FAQ实际上,他们已经在他们的常见问题解答中回答了这个问题
I needed to turn off eslint's, no-unused-vars
rule, and turn on the typescript-eslint
rule.我需要关闭 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.