在 JHipster 应用程序中声明任何 TypeScript 枚举时出现 no-shadow 误报
no-shadow False positive when declaring any TypeScript enum in JHipster app
我想在我的应用程序中使用枚举:
export const enum typeEnum {
TVY = 'TVY',
USER = 'USER',
}
在 npm 运行 webpack:build,我得到以下错误:
12:111 error 'typeEnum' is already declared in the upper scope
no-shadow
我阅读了几个与此错误相关的 link 解决方案是将以下内容添加到 eslint 规则中:
"no-shadow": "off",
"@typescript-eslint/no-shadow": "error"
这就是我在 .eslintrc.json 文件中所做的:
{
"plugins": ["@typescript-eslint/tslint"],
"extends": ["jhipster"],
"parserOptions": {
"project": "./tsconfig.base.json"
},
"rules": {
"@typescript-eslint/tslint/config": [
"error",
{
"lintFile": "./tslint.json"
}
],
"@typescript-eslint/no-unused-vars": [
"warn",
{
"vars": "all",
"args": "after-used",
"ignoreRestSiblings": false
}
],
"@typescript-eslint/no-non-null-assertion": "off",
"no-shadow": "off",
"@typescript-eslint/no-shadow": "error"
}
}
但是现在,我在 npm 运行:webpack:build :
也遇到了这个错误
myPath\src\main\webapp\app\vendor.ts [INFO] 1:1 error Definition
for rule '@typescript-eslint/no-shadow' was not found
@typescript-eslint/no-shadow
你知道我能做什么吗?
谢谢,
曼努埃拉
解决方案是只添加:
"no-shadow": "off"
该错误基本上意味着您在更高级别的某处(可能在全局范围内)有另一个同名的枚举。尝试重命名您的枚举并查看。
顺便说一句。关闭规则是一种不好的做法。 TS/ES linters 说你的代码哪里有问题。在大多数情况下,您必须修复代码中的问题,而不是仅仅关闭 linter。
原来你需要关闭标准 eslint 规则,而是使用 TypeScript-specific 值。
"no-shadow": "off",
"@typescript-eslint/no-shadow": ["error"],
- 此处注明:https://github.com/typescript-eslint/typescript-eslint/issues/2483
- eslint 规则:https://eslint.org/docs/rules/no-shadow
- TypeScript 规则:https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-shadow.md
(我刚刚 运行 遇到这个问题,做了这个改变,它为我解决了)
我想在我的应用程序中使用枚举:
export const enum typeEnum {
TVY = 'TVY',
USER = 'USER',
}
在 npm 运行 webpack:build,我得到以下错误:
12:111 error 'typeEnum' is already declared in the upper scope no-shadow
我阅读了几个与此错误相关的 link 解决方案是将以下内容添加到 eslint 规则中:
"no-shadow": "off",
"@typescript-eslint/no-shadow": "error"
这就是我在 .eslintrc.json 文件中所做的:
{
"plugins": ["@typescript-eslint/tslint"],
"extends": ["jhipster"],
"parserOptions": {
"project": "./tsconfig.base.json"
},
"rules": {
"@typescript-eslint/tslint/config": [
"error",
{
"lintFile": "./tslint.json"
}
],
"@typescript-eslint/no-unused-vars": [
"warn",
{
"vars": "all",
"args": "after-used",
"ignoreRestSiblings": false
}
],
"@typescript-eslint/no-non-null-assertion": "off",
"no-shadow": "off",
"@typescript-eslint/no-shadow": "error"
}
}
但是现在,我在 npm 运行:webpack:build :
也遇到了这个错误myPath\src\main\webapp\app\vendor.ts [INFO] 1:1 error Definition for rule '@typescript-eslint/no-shadow' was not found @typescript-eslint/no-shadow
你知道我能做什么吗?
谢谢,
曼努埃拉
解决方案是只添加:
"no-shadow": "off"
该错误基本上意味着您在更高级别的某处(可能在全局范围内)有另一个同名的枚举。尝试重命名您的枚举并查看。
顺便说一句。关闭规则是一种不好的做法。 TS/ES linters 说你的代码哪里有问题。在大多数情况下,您必须修复代码中的问题,而不是仅仅关闭 linter。
原来你需要关闭标准 eslint 规则,而是使用 TypeScript-specific 值。
"no-shadow": "off",
"@typescript-eslint/no-shadow": ["error"],
- 此处注明:https://github.com/typescript-eslint/typescript-eslint/issues/2483
- eslint 规则:https://eslint.org/docs/rules/no-shadow
- TypeScript 规则:https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-shadow.md
(我刚刚 运行 遇到这个问题,做了这个改变,它为我解决了)