【问题标题】:declaring enum in typescript gives me error在打字稿中声明枚举给了我错误
【发布时间】:2021-11-10 02:38:52
【问题描述】:

在第 26 行的打字稿文件中,我有以下代码:

export enum ItemType {
  Case = 'Case',
  Study = 'Study',
  Project = 'Project',
  Item = 'Item',
}

我使用 Visual Studio Code 作为 IDE。 linting 给了我一个错误'ItemType' is already declared in the upper scope on line 26 column 13.eslint(no-shadow)

ItemType 被引用的唯一地方是下面接口定义的同一文件中:

export interface Item {
  // other fields here

  readonly type: ItemType;
}

在我的项目中,没有任何其他地方可以定义任何称为“ItemType”的东西。这就是让理解这个错误变得困难的原因。为什么会出现此错误,如何修复我的代码?

【问题讨论】:

标签: typescript


【解决方案1】:

我能够使用您的代码在最小的环境中复制 @typescript-eslint/parser 的问题。不确定您使用的是什么 linting-rules 或 styleguides,但将以下规则添加到我的 eslintrc.js 文件中可以解决问题

"rules": {
    "no-shadow": "off",
    "@typescript-eslint/no-shadow": "off"
}

【讨论】:

    猜你喜欢
    • 2014-05-29
    • 1970-01-01
    • 2016-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多