Make complierOptions generate warnings instead of errors in tsconfig
Asked Answered
B

1

19

Is there a way to indicate in the tsconfig.json file the options noUnusedLocals and noUnusedParameters as warnings instead of errors that block the compilation?

Currently I use them in the tsconfig.json file like this :

  "compilerOptions": {
    "noUnusedLocals": true,
    "noUnusedParameters": true
  },

I tried the option :

"no-unused-variable": true,

in the tslint.json file but it doesn't detect errors like the tsc, and in visual studio code I can't see them underlined.

Begrime answered 30/7, 2018 at 12:56 Comment(0)
T
9

As you may have seen, Visual Studio Code has a hack to display noUnusedLocals and noUnusedParameters problems as warnings during live editing (the typescript.reportStyleChecksAsWarnings setting, which defaults to true). The tslint extension does not display these problems at all because they require type information, which the tslint extension does not support.

If the issue is that you are using something like tsc --noEmitOnError and you don't want noUnusedLocals/noUnusedParameters errors to block the emit, then you could have Visual Studio Code use one tsconfig.json that has noUnusedLocals/noUnusedParameters enabled and have your command line builds use tsc with a separate tsconfig.json that has the options disabled, plus tslint with no-unused-variable.

Trireme answered 30/7, 2018 at 14:14 Comment(2)
in a team where multiple people touch the tsconfig file, this becomes very easily error-prone. Is it still the recommended solution?Biondo
Yes this is a dilemma. The linter and vs code plugin should support it as warning. Or tsconfig (for specific rules). The best solution could be to switch to eslint if possible. Since tslint is (officially) deprecated in favor of eslint. Typescript is supported by plugin.Weightless

© 2022 - 2024 — McMap. All rights reserved.