Reputation: 2388
I'm using ESLint with TypeScript. When I try to create a function type with some required parameters, ESLint shows error eslint: no-unused-vars
.
type Func = (paramA: number) => void
Here, paramA is un-used variable according to ESLint.
My .eslintrc.json
file
{
"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?
Upvotes: 6
Views: 2825
Reputation: 3936
As mentioned in the document of typescript-eslint, disabled the rule from eslint and enable from 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"]
}
Upvotes: 12
Reputation: 2388
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.
"rules": {
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "error"
}
Upvotes: 1
Reputation: 402
If I understood you correctly, what you're trying to do is
const func: (paramA: number) => void
to define a function type.
Upvotes: 0