Node.js – Eslint says all enums in Typescript app are “already declared in the upper scope”

eslintnode.jstypescript

Starting a new application, I installed eslint and configured it with the following configs, but every time I create an enum it says it had already been defined. Even nonsense strings. Other variable types (const, var, let) don't have this issue. I could disable the rule but I would like it applied for situations where it is actually true.

    {
  "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
      }
    ]
  }
}

enter image description here

Best Answer

If you are a user of TSLint-to-ESLint this was a bug that has since been fixed so rerunning the script with a newer version would also fix the issue, or just disable the no-shadow and enable @typescript-eslint/no-shadow

If you are using some public config that is misusing the rule then be sure to let them know, the number of people still running into this is somewhat staggering.


see @typescript-eslint/no-shadow how to use also this section of FAQ

How to use

{
  // note you must disable the base rule as it can report incorrect errors
  "no-shadow": "off",
  "@typescript-eslint/no-shadow": ["error"]
}

Searching typescript-eslint GitHub issues shows a number of people asking the same thing.

Related Topic