Ada*_*mes 74 node.js typescript eslint
启动一个新应用程序,我安装了 eslint 并使用以下配置对其进行了配置,但是每次我创建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
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
Tad*_*sen 91
如果您是 TSLint-to-ESLint 的用户,这是一个已修复的错误,因此使用较新版本重新运行脚本也可以解决该问题,或者只是禁用no-shadow并启用@typescript-eslint/no-shadow
看到@打字稿,eslint /无阴影如何使用 也是常见问题本节
{
// note you must disable the base rule as it can report incorrect errors
"no-shadow": "off",
"@typescript-eslint/no-shadow": ["error"]
}
Run Code Online (Sandbox Code Playgroud)
搜索typescript-eslint GitHub 问题会发现很多人都在问同样的问题。
lib*_*iby 29
Tadhg McDonald-Jensen 的回答很有用,但有一点需要说明。直接写入以下配置项.eslintrc会报错:
{
// note you must disable the base rule as it can report incorrect errors
"no-shadow": "off",
"@typescript-eslint/no-shadow": ["error"]
}
Run Code Online (Sandbox Code Playgroud)
这是一个带有无阴影规则的正确示例:
{
"rules": {
"no-shadow": "off",
"@typescript-eslint/no-shadow": ["error"]
},
}
Run Code Online (Sandbox Code Playgroud)
Kos*_*aft 12
我在 TypeScript 中使用以下代码时遇到了类似的问题:
\nexport enum MyEnum {\n myValueOne = \'myValue\',\n myValueTwo = \'myValueTwo\', // <-- got "already declared in the upper scope\xe2\x80\x9d error\n}\n\nexport class myValueTwo {\n constructor(){}\n}\nRun Code Online (Sandbox Code Playgroud)\n不幸的是rules,两者都overrides没有解决问题
{\n "rules": {\n "no-shadow": "off",\n "@typescript-eslint/no-shadow": ["error"]\n },\n "overrides": {\n "no-shadow": "off",\n "@typescript-eslint/no-shadow": ["error"]\n },\n}\nRun Code Online (Sandbox Code Playgroud)\n在花了几个小时检查不同的问题、问题和有关该问题的文档后,我发现了@typescript-eslint/no-shadow. 链接在这里
我要做的就是ignoreTypeValueShadow在 eslint for 中添加额外的选项@typescript-eslint/no-shadow。
我的无阴影最终设置如下所示:
\n{\n "overrides": {\n "no-shadow": "off",\n "@typescript-eslint/no-shadow": ["error", , { "ignoreTypeValueShadow": true }]\n },\n}\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
22474 次 |
| 最近记录: |