37

After eslint adds typescript check, there will be an error when the attribute variable in the class definition is Array. enter image description here

enter image description here

enter image description here


this is my eslintrc.js

module.exports = {
  root: true,
  env: {
    node: true
  },
  'extends': ['plugin:vue/essential', '@vue/standard'],
  rules: {},
  parserOptions: {
    parser: '@typescript-eslint/parser',
    project: "./tsconfig.json"
  },
  plugins: ['@typescript-eslint']
};
Christopher Moore
  • 3,071
  • 4
  • 30
  • 46
Jian Cl
  • 373
  • 1
  • 3
  • 4
  • this is my eslintrc.js – Jian Cl Mar 21 '19 at 12:35
  • module.exports = { root: true, env: { node: true }, 'extends': [ 'plugin:vue/essential', '@vue/standard' ], rules: { }, parserOptions: { parser: '@typescript-eslint/parser', project: "./tsconfig.json" }, plugins: ['@typescript-eslint'] }; – Jian Cl Mar 21 '19 at 12:35
  • You should really put your code in your post rather than use images. It makes it easier for people to debug. – Doug F Mar 21 '19 at 12:39
  • ok i will show my code – Jian Cl Mar 22 '19 at 07:33

3 Answers3

64

The solution is to disable the native no-unused-vars so that only the TS one is enabled. The former is likely to be enabled if you extend a config in ESLint. Add the rules below to your ESLint config.

"rules": {
  "no-unused-vars": "off",
  "@typescript-eslint/no-unused-vars": "error"
}
James Middleton
  • 679
  • 1
  • 5
  • 8
  • 1
    How can one make sure only to omit the errors on imports? – Casper Nybroe Sep 29 '20 at 09:46
  • Its an old answer but this is not a solution, since via this nothing is checked for unused variables, intention is to pass the rule for the types being used in some Generics and fails the rule when someone declared the variable and not used. I want to apply the rule of _ to ignore the variable, this does not supports, if I configures it with the rules of https://eslint.org/docs/rules/no-unused-vars then it starts complaining for unused TYPES. – Ankur Verma Apr 21 '21 at 08:32
56

Updated Answer

Disable no-unused-vars and enable it with "@typescript-eslint/no-unused-vars": "error"

"rules": {
  "no-unused-vars": "off",
  "@typescript-eslint/no-unused-vars": "error"
}

Thanks to James Middleton for the correct answer.

Outdated

Looking at the eslint repository on github, there have been lots of issues opened about the no-unused-vars rule. Here is some examples:

https://github.com/typescript-eslint/typescript-eslint/issues/45

https://github.com/typescript-eslint/typescript-eslint/issues/111

https://github.com/typescript-eslint/typescript-eslint/issues/171

It's an ongoing problem. Hopefully we can expect this to be resolved soon.

Parker Tailor
  • 1,290
  • 13
  • 12
  • 1
    This worked for me as well. However, I still had to make sure to not only update `@typescript-eslint/eslint-plugin`, but also `@typescript-eslint/parser` (version 4.12.0 for both in my case) to make it work without any false positives. – Patrick Jan 05 '21 at 09:56
1

If someone are still having the issue, I add "extends": ["eslint:recommended", "plugin:react/recommended"], on the .eslintrc.json file and the problem get solved.