我正在将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中创建函数类型的正确方法是什么?
预先感谢
答案 0 :(得分:1)
如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"]
}
答案 1 :(得分:0)
如果我对您的理解正确,那么您想做的就是
const func: (paramA: number) => void
定义函数类型。
答案 2 :(得分:0)