【问题标题】:no-shadow False positive when declaring any TypeScript enum in JHipster app在 JHipster 应用程序中声明任何 TypeScript 枚举时出现误报
【发布时间】:2021-02-04 08:27:13
【问题描述】:

我想在我的应用中使用枚举:

export const enum typeEnum {
  TVY = 'TVY',

  USER = 'USER',
}

在 npm run webpack:build 时,我收到以下错误:

12:111 错误 'typeEnum' 已在上层范围内声明 无阴影

我在几个与此错误相关的链接上读到,解决方案是将以下内容添加到 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 run:webpack:build 也收到此错误:

myPath\src\main\webapp\app\vendor.ts [INFO] 1:1 错误定义 找不到规则“@typescript-eslint/no-shadow” @typescript-eslint/无阴影

你知道我能做什么吗?

谢谢,

曼努埃拉

【问题讨论】:

    标签: typescript jhipster eslint


    【解决方案1】:

    原来你需要关闭标准的 eslint 规则,而是使用 TypeScript 特定的值。

    "no-shadow": "off",
    "@typescript-eslint/no-shadow": ["error"],
    

    (我刚遇到这个问题,做了这个更改,它为我解决了它)

    【讨论】:

      【解决方案2】:

      该错误基本上意味着您在更高级别(可能在全局范围内)有另一个同名的枚举。尝试重命名您的枚举并查看。

      顺便说一句。关闭规则是一种不好的做法。 TS/ES linter 指出你的代码哪里有问题。在大多数情况下,您必须解决代码中的问题,而不是仅仅关闭 linter。

      【讨论】:

      • 这是枚举造成的误报。我没有任何其他同名的,这是肯定的。这是一个已知问题。不幸的是,在不关闭“无阴影”规则的情况下,我没有找到任何解决方法。 github.com/typescript-eslint/typescript-eslint/issues/2484
      • 你为什么要const enum?为什么不只是enum
      【解决方案3】:

      解决方案是只添加:

       "no-shadow": "off" 
      

      【讨论】:

        猜你喜欢
        • 2021-01-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-08-22
        • 1970-01-01
        • 1970-01-01
        • 2015-04-26
        • 1970-01-01
        相关资源
        最近更新 更多