-
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
Ignore specified error in //@ts-ignore #21602
Conversation
sorry for linting issues, fixing them |
I actually suggested this in the original PR, but the author said he didn't like the idea because you can't tell what is being ignored by just the error code. |
src/compiler/program.ts
Outdated
@@ -3,7 +3,7 @@ | |||
/// <reference path="core.ts" /> | |||
|
|||
namespace ts { | |||
const ignoreDiagnosticCommentRegEx = /(^\s*$)|(^\s*\/\/\/?\s*(@ts-ignore)?)/; | |||
const ignoreDiagnosticCommentRegEx = /(^\s*$)|(^\s*\/\/\/?\s*(@ts-ignore)?(?:\s+((?:(?:TS\d+),\s*)*(?:TS\d+)?))?)/; |
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.
The ?
in (?:TS\d+)?
is redundant (causes an extra backtrack into a 0-length match, which is already allowed by the ?
in the outer non-capturing match)
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.
agree, thanks, I'll remove it later
Error codes are public now, they printed berfore error message in error report. Imho blindly ignore everything is very dangerous and not good idea. Ignoring is always not good idea, but additional safety is not superfluous, we are at TypeScript repository, right? |
Another suggestion: |
Don't you have to split the provided string at the We have cases like this: TS9002 Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clause. and TS90020 Initialize property '{0}' in the constructor In this case, if we have a TS9002 and a comment |
@lmcarreiro yes, you are right. I`ll fix it |
Your regex doesn't match error codes with spaces before comma: |
Thanks @Busyrev for the contribution. We have had another heated discussion about this topic in the last language design meeting (see notes in #22011). The conclusion is we could not reach consensuses whether this feature should be added or not. It boils down to concerns about using error numbers, and how they do not add to expressiveness in a position like such. It is a discussion we have once every quarter or so, including when we first added support for ignoring errors. I am sure we will come to it again in the near future. |
@mhegazy no problem, I can use my own fork :). For discussion I think that short text error idents, like in tslint, would be better. But someone should create them. |
👍 Thank you 😍 This is one if the points we keep going back to 😉 |
closing for now. |
Fixes #21197
Special syntax available now:
to ignore only "Cannot invoke an expression whose type lacks a call signature." error.
Comma separated list supported, trailing comma is supported too:
If no error code specified, it ignores all errors.