Support @ts-ignore for specific errors
See original GitHub issueTypeScript Version: 2.6.0-dev.20171011
Code
function countDown(n: number): void {
switch (n) {
// @ts-ignore
case 1:
console.log("1");
// intentional fall through
case 0:
console.log("0");
}
}
Expected behavior:
Ability to make ts-ignore
apply to the --noFallthroughCasesInSwitch
error but not to other errors.
Actual behavior:
case "1":
would also compile.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:420
- Comments:94 (17 by maintainers)
Top Results From Across the Web
Ignore certain TypeScript compile errors? - Stack Overflow
The underlying problem I have is that I need to guarantee that all logic is within a consistent scope, I need to be...
Read more >Ignore Typescript error* - Aishwarya Shrestha - Medium
// @ts-ignore comment enables the Typescript compiler to ignore the line below it, in this way you can ignore errors on specific lines...
Read more >How To Ignore The Next Line In TypeScript? - Tim Mousk
To ignore all TypeScript compiler errors of a file, add a @ts-nocheck comment at the top of the file. ... This comment will...
Read more >Force TypeScript Compiler to Ignore Errors - DevX
Use the “@ts-ignore” comment before the code and the compiler will ignore errors. // @ts-ignoreimport mathUnit from 'mathjs/lib/type/unit'.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m repeatedly coming back to this issue.
@ts-expect-error
doesn’t make sense without specifying the error. I don’t mind that@ts-ignore
can’t be narrowed down, eslint’s default rules prohibit@ts-ignore
anyway. The problem with@ts-ignore
is the implicit cleanup condition. But@ts-expect-error
makes a lot of sense a lot of times with narrowing it down to one specific error. Eslint expects me to add a comment as well. But expecting any error makes the flag unsafe. So what’s the point then?Having said this, all the places where I see a reaction from a TS representative, I see wrong arguing. Focusing on
@ts-ignore
, bringing in short names (why?)…I see 3 problems with this (at least):
It’s arguing with extremes. Having hundreds of @ts-expect-error on one particular error type in a codebase feels like a fishy case, but quite uncommon at least. And even then, I don’t see a problem with search-and-replacing those comments. Also how common is that TS changes an error code for the same error condition? Has it even ever happened?
Also, narrowing down
@ts-expect-error
is the developer’s responsibility with all the consequences.It’s indeed counterintuitive that error codes are tied to the error text. Why is that? Nobody expects that errors are defined by their text. Everybody treats the text as prone to being changed over time. That’s why there’s a code. On the other hand, introducing a new code for the same error already adds inconsistency to the global TS knowledge - think about googling new error codes not matching the results for the old one; and then maintaining a code history on all the blog posts and help pages on the internet, which explains a particular error…
The only actual argument, if I’m not mistaken, is the instability of the error codes.
A couple thoughts
All we are asking for is the ability to ignore those errors that we deem to be more style than error especially when the code actually runs, yet not have to not turn everything off.
The general reply in effect is that it is a bad idea to turn off errors but if you have to then turn them all off which makes no sense at all whether at the global or individual line level.
What would the actual level of effort be to implement ignorable/expectable error codes at the comment AND tsconfig level for consistency?
If it were implemented, would the folks in this thread be ok with the ts compiler generating a report of ignored errors that could in some way (via opt-in program) reported back to the ts dev team so that they can have some real world feedback on what all is getting ignored?
My problem with suggestions like “we are not seeing issues with …” is that you aren’t looking at any real code. You are waiting for the rarified people who know enough to complain, and with enough time to, to actually complain. To make those kind of arguments you need real feedback but if you are making it so we can’t know what the errors we’re ignoring are, except all of them, then how can you possibly know that your errors are useful or what the consequences of your choices are?
I’m thinking there is an opportunity for a meaningful feedback loop and a win-win if you let us codify our overrides inline with some metric info going back to you rather than have to come here to complain about things,
// @ts-ignore TS/1234 because I know what I’m doing Seems a lot more reasonable than // @ts-ignore developers Which leads to // @ts-expect-error typescript devs do not care so neither should we