TypeScript linter warning: no-unused-variable is deprecated; but I'm not using this config
Asked Answered
K

3

48

Today I see this warning in a project being refreshed after 3 months.

no-unused-variable is deprecated. Since TypeScript 2.9. Please use the built-in compiler checks instead.

But my tsconfig.json does not seem to use this.

{
  "compilerOptions": {
    "lib": ["es6"],
    "module": "commonjs",
    "noImplicitReturns": true,
    "outDir": "lib",
    "sourceMap": true,
    "target": "es6",
    "allowJs" : true
  },
  "compileOnSave": true,
  "include": [
    "src"
  ]
}

Probably it's a config implicit in any of the previous configs.

Could you point me to what to do to fix it?

If usefull

$ node -v
v10.3.0
$ npm -v
6.1.0

And these are devDependencies relates to type script in my package.json

"devDependencies": {
    ...
    "tslint": "^5.11.0",
    "typescript": "^2.9.1"
    ...
  },
Karlynkarma answered 31/7, 2018 at 19:59 Comment(1)
It's a TSLint warning. Look in the tslint.json file for the rule configurations.Nephro
C
73

no-unused-variable is deprecated. Since TypeScript 2.9. Please use the built-in compiler checks instead.

  1. Remove deprecated no-unused-variable from your or dependency tslint.json file.

  2. Specify the following compiler options in your tsconfig.json file.

"compilerOptions": {
  "noUnusedLocals": true,                /* Report errors on unused locals. */
  "noUnusedParameters": true             /* Report errors on unused parameters. */
}
Calcic answered 5/12, 2019 at 10:43 Comment(3)
Tested. Best answer.Columella
how to use this rule inline? that my question.Porcelain
thank you! I was confused as I thought tsc compilation reads eslint rules, and I had no-unused-vars turned off there, but it turns out that I need this in tsconfigMichele
B
37

As it says, tslint deprecated that rule (more info here https://github.com/palantir/tslint/pull/3919)

Check your tslint.json, and remove the rule and the warning should disappear.

Baxter answered 31/7, 2018 at 20:10 Comment(5)
Thanks. I checked tsconfig.json but not checked tslint.json.Karlynkarma
But what does Please use the built-in compiler checks instead. mean?Nail
@ThomasEbert this means adding noUnusedLocals/noUnusedParameters to compilerOptions in tsconfig.json.Hasin
@migg has the real answer here. Don't just remove the rule without adding this.Lament
This doesn't seem like it should be deprecated, though, as noUnusedLocals does NOT catch unused imports, while no-unused-variable DOES catch unused imports.Periphrasis
H
9

Not only support for no-unused-variable rule, but the whole TSLint has been deprecated in favor of typescript-eslint.

Consider migration to new linter.

Hermitage answered 2/12, 2019 at 11:3 Comment(1)
Note that at the time of writing of this comment, Angular is still uses TSLint by default. The migration for Angular is still in progress. So Angular users might still want to stick TSlint for a short while until the Angular team is done with migrating.Enjambment

© 2022 - 2024 — McMap. All rights reserved.