Yus*_*bek 6 javascript typescript eslint
我将 ESLint 与 TypeScript 结合使用。当我尝试创建带有一些必需参数的函数类型时,ESLint 显示 error 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": {
}
}
Run Code Online (Sandbox Code Playgroud)
那么,使用 ESLint 在 TypeScript 中创建函数类型的正确方法是什么?
Shi*_*dey 12
正如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"]
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2466 次 |
| 最近记录: |