Possibility of Suppressing any error (e.g. incl. TS7017) within a config file (e.g. tsconfig.json)
Asked Answered
B

4

25

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.

Bookman answered 21/9, 2016 at 13:19 Comment(1)
Can TypeScript v4++ help?Bookman
P
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

Passably answered 21/9, 2016 at 23:15 Comment(1)
Seems like your issue was closed with reference to another issue which is also closed and still we can't suppress specific errors in a config file lolIcken
C
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.

Compiler answered 12/8, 2018 at 13:37 Comment(1)
Thank you, i have been looking everywhere for this. Other comments like // tslint:disable-next-line did not workDekker
J
2

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

See tsconfig schema for more details

Jsandye answered 21/9, 2016 at 13:44 Comment(3)
Thank you but I would like to suppress any desired error, TS7017 is only an example.Bookman
@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, typescriptlang.org/docs/handbook/compiler-options.htmlHexahydrate
Thanks, I've changed the title into a verbose oneBookman
G
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

Greybeard answered 22/9, 2016 at 4:4 Comment(3)
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.Bookman
Use --suppressImplicitAnyIndexErrors for that. see the compiler option documentation page for that: typescriptlang.org/docs/handbook/compiler-options.htmlGreybeard
TS2403 would be convenient to suppress for third-party codePortamento

© 2022 - 2024 — McMap. All rights reserved.