1

In a typescript file at line 26 I have the following code:

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

I am using Visual Studio Code as the IDE. The linting gives me an error 'ItemType' is already declared in the upper scope on line 26 column 13.eslint(no-shadow)

The only place where ItemType is referenced is below in the same file in an interface definition:

export interface Item {
  // other fields here

  readonly type: ItemType;
}

Nowhere else in my project do I have a definition of anything called 'ItemType'. This is what makes understanding this error difficult. Why do I get this error, and how do I fix my code?

Tibi
  • 439
  • 7
  • 15
  • Does this answer your question? [Eslint says all enums in Typescript app are "already declared in the upper scope"](https://stackoverflow.com/questions/63961803/eslint-says-all-enums-in-typescript-app-are-already-declared-in-the-upper-scope) – Fraser Sep 15 '21 at 00:36

2 Answers2

3

You need to turn off the regular no-shadow eslint rule and replace it with the typescript-eslint one.

So add this to your eslint configuration:

...
"no-shadow": "off",
"@typescript-eslint/no-shadow": ["error"],
...
Raul Špilev
  • 288
  • 4
  • 18
-1

I was able to replicate the issue with the @typescript-eslint/parser in a minimal env with your code. Not sure what linting-rules or styleguides you're using but adding the following rules to my eslintrc.js file did the trick

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