ESLint未使用的varialbes规则,用于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

定义函数类型。

,

实际上,他们已经在自己的FAQ

中回答了这个问题

我需要关闭eslint的No规则,然后打开no-unused-vars规则。

typescript-eslint