Search code examples
typescriptjhipstereslint

no-shadow False positive when declaring any TypeScript enum in JHipster app


I want to use an enum in my app :

export const enum typeEnum {
  TVY = 'TVY',

  USER = 'USER',
}

At npm run webpack:build, I get the following error :

12:111 error 'typeEnum' is already declared in the upper scope no-shadow

I read on several link relative to this error that the solution was to add the following to the eslint rules :

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

This is what I did, in the .eslintrc.json file :

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

But now, I get this error also at npm run: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

Do you know what I can do?

Thanks,

Manuela


Solution

  • The error basically means you have another enum with the same name somewhere on level higher (probably in global scope). Try to rename your enum and look.

    BTW. Switching off rules is a bad practice. TS/ES linters say where your code have problems. In most cases you have to fix the problem in the code instead of just shut up the linter.