Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 956
Manuela CodingPadawan Avatar asked Oct 21 '20 12:10

Manuela CodingPadawan


2 Answers

Turns out that you need to turn off the standard eslint rule, and instead use a TypeScript-specific value.

"no-shadow": "off",
"@typescript-eslint/no-shadow": ["error"],
  • This is noted here: https://github.com/typescript-eslint/typescript-eslint/issues/2483
  • eslint rule: https://eslint.org/docs/rules/no-shadow
  • TypeScript rule: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-shadow.md

(I just ran into this problem, made this change, and it solved it for me)

like image 104
David Avatar answered Jan 01 '23 08:01

David


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.

like image 30
Roman Maksimov Avatar answered Jan 01 '23 10:01

Roman Maksimov