问题描述
我正在将ESLint与TypeScript一起使用。当我尝试使用一些必需的参数创建函数类型时,ESLint显示错误eslint: no-unused-vars
。
type Func = (paramA: number) => void
在这里,根据ESLint,paramA是未使用的变量。
{
"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
定义函数类型。
,实际上,他们已经在自己的FAQ
中回答了这个问题我需要关闭eslint的No
规则,然后打开no-unused-vars
规则。
typescript-eslint