-
Notifications
You must be signed in to change notification settings - Fork 12.8k
improve Diagnostics for accidentally calling type-assertion expressions #27020
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
improve Diagnostics for accidentally calling type-assertion expressions #27020
Conversation
maybe that could be a related Diagnostics? |
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, and great test cases! Can we make this a related span though?
src/compiler/checker.ts
Outdated
@@ -19655,6 +19655,13 @@ namespace ts { | |||
error(node, Diagnostics.Value_of_type_0_is_not_callable_Did_you_mean_to_include_new, typeToString(funcType)); | |||
} | |||
else { | |||
if (node.arguments.length === 1 && isTypeAssertion(first(node.arguments))) { | |||
const text = getSourceFileOfNode(node).text; | |||
const pos = skipTrivia(text, node.expression.end, /* stepAfterLineBreak */ true) - 1; |
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.
step -> stop
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.
Technically this function and isLineBreak
seem to have differing definitions of what a line break is...
...so I don't know if that's a problem 😅
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.
in CRLF
or LF
, the skipTrivia() - 1
will always correctly,
but if only CR
, that seems a problem...
src/compiler/checker.ts
Outdated
const text = getSourceFileOfNode(node).text; | ||
const pos = skipTrivia(text, node.expression.end, /* stepAfterLineBreak */ true) - 1; | ||
if (isLineBreak(text.charCodeAt(pos))) { | ||
error(node.expression, Diagnostics.It_is_highly_likely_that_you_are_missing_a_semicolon); |
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.
I agree! This should definitely be a related span if possible.
Thanks @Kingwl! |
Fixes #26991