Eslint说,TypeScrip应用程序中的所有枚举都已声明在较高的作用域中 [英] Eslint says all enums in Typescript app are "already declared in the upper scope"
本文介绍了Eslint说,TypeScrip应用程序中的所有枚举都已声明在较高的作用域中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
enum
时,它都会显示已经定义了它。甚至是胡说八道的字符串。其他变量类型(const、var、let)没有这个问题。我可以禁用该规则,但我希望它应用于它实际上为真的情况。
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"parserOptions": {
"project": ["./tsconfig.json"],
"ecmaFeatures": {
"ecmaVersion": 6,
"jsx": true
}
},
"overrides": [],
"extends": [
"airbnb-typescript",
"prettier",
"prettier/@typescript-eslint",
"plugin:@typescript-eslint/recommended-requiring-type-checking"
],
"rules": {
"spaced-comment": 0,
"import/prefer-default-export": 0,
"@typescript-eslint/no-use-before-define": 0,
"@typescript-eslint/restrict-template-expressions": [
1,
{ "allowBoolean": true }
],
"react/jsx-props-no-spreading": "off",
"react/state-in-constructor": 0,
"react/require-default-props": 0,
"react/destructuring-assignment": [
1,
"always",
{
"ignoreClassFields": true
}
]
}
}
推荐答案
如果您是TSLint-to-ESLint的用户,则这是a bug that has since been fixed,因此使用较新版本重新运行该脚本也可以解决该问题,或者只禁用no-shadow
并启用@typescript-eslint/no-shadow
如果您使用的某个公共配置滥用了规则,请务必让他们知道,仍然遇到此问题的人数有些惊人。
参见@typescript-eslint/no-shadow how to use 也this section of FAQ
如何使用
{
// note you must disable the base rule as it can report incorrect errors
"no-shadow": "off",
"@typescript-eslint/no-shadow": ["error"]
}
搜索typescript-eslint GitHub issues显示许多人提出相同的问题。
这篇关于Eslint说,TypeScrip应用程序中的所有枚举都已声明在较高的作用域中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文