2
votes

How can I find out which compiler option is associated with a given Typescript error?

I'm using Typescript in VSCode, and Typescript frequently points out problems, like initializer provides no value for this binding element

(Please note this is a warning generated by Typescript, not TSLint).

In tsconfig.json, I can turn off specific warnings, such as

"compilerOptions": {
  "noImplicitAny": false,
  "strictPropertyInitialization": false
}

But as far as I can tell, there's no way to find out which compiler option is associated with which error.

Clues so far, but no solution:

This SO post, Complete list of Typescript error codes and their fixes, provides a list of messages, but not with which compiler option en/disables the message.

And unfortunately, the names of the compiler options do not mimic the wording of the errors, so you can't find the error via simple intellisense within tsconfig.json.

Additionally, the official docs seem not to provide such an error-to-option mapping, either: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html , https://www.typescriptlang.org/docs/handbook/compiler-options.html .

So, just to restate the question: how can I find out which compiler option to turn off to silence a given error?

1

1 Answers

0
votes

There is not a 1:1 (or 1:n or n:1) correspondence between error messages and compiler settings, and the vast majority of errors cannot be turned off with any compiler option. Many compiler options change behavior in a way that mean you can't reliably say what would have happened counterfactually with some other set of options.

For the error messages that do have a corresponding flag, the error text usually hints at it

  • "x" implicitly has type 'any'noImplicitAny
  • Unreachable code detectedallowUnreachableCode
  • Unused label detectedallowUnusedLabels
  • "x" is possibly "null"strictNullChecks
  • Local "x" is unusednoUnusedLocals

etc