23

I would like to suppress any desired error; TS7017 is only an example.

Maybe it is possible now? Can TypeScript v4++ help?

I want to achieve something like (e.g., in the compilerOptions in tsconfig.json):

// ATTENTION PSEUDO CODE
suppressErrors: ['TS7017', ....]

(TS7017 is an example, it means: Index signature of object type implicitly has an 'any' type.)

Before anyone says the question doesn't make sense :)

No matter how absurd it sounds:

yes, I want to disable the fire alarm and intentionally set it on fire, because I have to test ( = management decision), how the people act, if there is fire, without a fire alarm.

4 Answers4

15

Suppressing certain errors

There is no option for that at the moment. I've created an issue to track it : https://github.com/Microsoft/TypeScript/issues/11051

basarat
  • 261,912
  • 58
  • 460
  • 511
15

As of TypeScript 2.6 (released on Oct 31, 2017), there is a way to ignore all errors from a specific line using // @ts-ignore comments before the target line.

The mendtioned documentation is succinct enough, but to recap:

// @ts-ignore
const s : string = false

disables error reporting for this line.

As for specifying certain errors, the current state is discussed here, in Design Meeting Notes (2/16/2018) and further comments, which is basically

"no conclusion yet"

and strong opposition to introducing this fine tuning.

stsloth
  • 1,670
  • 2
  • 18
  • 18
  • Thank you, i have been looking everywhere for this. Other comments like // tslint:disable-next-line did not work – Ka Tech Nov 04 '21 at 11:20
2

This specific error message is a noImplicitAny error message. that means you have passed --noImplicitAny to the compiler. if you so desire to shut it off, then do not set the flag.

One thing to note is that the TypeScript compilers errors do not impact your output. the output is generated regardless. so if you wish to ignore all errors, you can.

The errors for things that are tangential to the type system work are all managed by flags, e.g. noImplicitAny, noImplictThis, noUnusedLocals, noUnusedPrameters, noImplicitReturs, etc..

Other errors are a signal from the compiler that something went wrong during checking your code. silencing the error does no guarantee that the type system has i\correctly understood your code. this does not guarantee that your program is consistent, or, and this is more important, that you will not get explainable errors in other parts of the system.

I would be intrested to know what specific errors you find superflous, and would like to suppress

mohamed hegazy
  • 9,191
  • 4
  • 30
  • 21
  • 1
    everything related to `this` like `this[whatever]` which is syntactically and semantically correct, outputs TS7017 Error. I can suppress that with `(this as any)[whatever]`, that is my current solution and it was (I think) your idea at Microsoft's Platform. –  Sep 22 '16 at 09:45
  • Use `--suppressImplicitAnyIndexErrors` for that. see the compiler option documentation page for that: http://www.typescriptlang.org/docs/handbook/compiler-options.html – mohamed hegazy Sep 23 '16 at 23:37
  • TS2403 would be convenient to suppress for third-party code – Kevin Beal Mar 06 '19 at 16:18
1

You can use "suppressImplicitAnyIndexErrors": true in compilerOptions if you want to suppress this specific error.

See tsconfig schema for more details

Aleksey L.
  • 35,047
  • 10
  • 74
  • 84
  • Thank you but I would like to suppress any desired error, TS7017 is only an example. –  Sep 21 '16 at 14:31
  • 1
    @Lonely The title of your question says 'Suppressing **certain** errors' — which errors do you want to suppress? The only other error suppression option I know of is `--suppressExcessPropertyErrors`, maybe that can help. BTW, https://www.typescriptlang.org/docs/handbook/compiler-options.html – Fabian Lauer Sep 21 '16 at 18:16
  • Thanks, I've changed the title into a verbose one –  Jul 28 '22 at 12:30