-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added @ts-expect-error to @ts-ignore directives #36014
Conversation
152655c
to
9918231
Compare
Similar to `// @ts-ignore`, but will itself cause a new error diagnostic if it does not cause an existing diagnostic to be ignored. Technical summary: 1. The scanner will now keep track of `CommentDirective`s it comes across: both `@ts-expect-error` and `@ts-ignore` 2. During type checking, the program will turn those directives into a map keying them by line number 3. For each diagnostic, if it's preceded by a directive, that directive is marked as "used" 4. All `@ts-expect-error` directives not marked as used generate a new diagnostic error
9918231
to
eb5610a
Compare
I'd like to try this in a playground: @typescript-bot perf test |
Heya @orta, I've started to run the perf test suite on this PR at eb5610a. You can monitor the build here. It should now contribute to this PR's status checks. Update: The results are in! |
@orta Here they are:Comparison Report - master..36014
System
Hosts
Scenarios
|
Re that On-Demand Benchmark test failure: Monaco check time went up 7.14% (line link). but emit time decreased by almost as much (31s out of 36s), and the total time went up only by 0.57%:
...so this feels like it's not a serious performance degradation, and this PR is still valid? 😁 |
This is great! @JoshuaKGoldberg I've also been toying around with implementing this. However, I was making I added the
And then I parse it in
( While I couldn't find a formal definition of "pragmas" in programming languages, in some programming languages, a "pragma" can be in places other than just the top of the file (https://dlang.org/spec/pragma.html). Here's my in progress diff: https://gist.github.com/davidgomes/5cb71342b6d2cf95ffa05a767eb802c7 |
I’d love to have something more powerful: //@ts-expect-error 2322 "Type 'number' is not assignable to type 'never'." Maybe with the option to omit trailing characters of the message and/or the error number. The former could be achieved via regular expressions: //@ts-expect-error 2322 /^Type 'number' is not assignable to type 'never'\.$/ Rationale: It’s not only a problem to expect errors where there aren’t any, but also to expect the wrong kind of error. |
Re-running perf tests, I'm not really convinced this could add 7% after reading the PR @typescript-bot perf test |
Heya @orta, I've started to run the perf test suite on this PR at 7a5ef8a. You can monitor the build here. Update: The results are in! |
Hey @orta, I've packed this into an installable tgz. You can install it for testing by referencing it in your
and then running There is also a playground for this build. |
@orta Here they are:Comparison Report - master..36014
System
Hosts
Scenarios
|
These numbers make more sense to me - basically everything is varying in the 0.x range on a plus or minus which is basically just normal noise in perf tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, happy to merge based on your answer to the my comment above
This would make it possible to deprecate It would also reduce noise in IDEs, as |
OK, this looks good to go - thanks! I don't know if it's in TypeScript, or in vscode, but we should also get The playground doesn't show any of those options. |
👍 It's in vscode, in a list of directives: microsoft/vscode#92093 |
I love this! Does this mean we can use |
I think so, yep |
As someone else already mentioned, I second that it would be nice to be able to specify exactly what error to expect (by its id/code etc). I've only used ts-ignore a few times but have already ran into the problem where I think I'm ignoring one error just to have it transform into another completely unrelated error however, unknowingly, since this transformation happened in "the meantime" while the ts-ignore directive was still active/in-place the whole time. So the new error that the old error "transformed into" went completely unnoticed from what I remember (until I removed the directive of course, which was when I found out about the change). Now I try to just avoid ts-ignore altogether because of such potential situations that may arise because it's just not worth taking that kind of a risk imo. |
related to @Tyler1205 's comment I would like to be able to specify number of errors, and that might be easier to handle. |
I agree, this is really needed as you can never know if you are blocking more than 1 error, or the wrong kind of error |
Similar to
// @ts-ignore
, but will itself cause a new error diagnostic if it does not cause an existing diagnostic to be ignored.Technical summary:
CommentDirective
s it comes across: both@ts-expect-error
and@ts-ignore
@ts-expect-error
directives not marked as used generate a new diagnostic errorFixes #29394