-
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
Improved error message for calling/constructing types #32034
Improved error message for calling/constructing types #32034
Conversation
Diagnostics.Cannot_invoke_an_expression_whose_type_lacks_a_call_signature_Type_0_has_no_compatible_call_signatures : | ||
Diagnostics.Cannot_use_new_with_an_expression_whose_type_lacks_a_call_or_construct_signature | ||
), typeToString(apparentType)); | ||
const diagnostic: Diagnostic = createDiagnosticForNodeFromMessageChain(node, invocationErrorDetails(apparentType, kind)); |
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.
What's with the annotation?
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.
Mistake, will delete
I really like this improvement, but I'm starting to get uneasy about the wording.
|
In other words, can we find better wording that refers to the invoked expression without sounding terrible? |
@DanielRosenwasser Personally I think the range of this error would be better on the target. I think it would make the most sense, the problem is with the target of the call, the arguments have no bearing on the error and are just extra noise. Unlike for example when overload selection fails when it makes sense to highlight the whole call expression since the problem is with the combination of call target and arguments. I think changing the target might cause some problems with some quick fixes ( |
@DanielRosenwasser Sure I will look into it. Not sure about a time line, this week is a bit busy though. |
9ae2feb
to
52897db
Compare
What do programmers do Friday night ? They code for fun 😁 I had a chance to finish the changes we discussed above to error spans. The behavior will be as follows:
declare const test: string;
test();
~~~~
declare const o: { test: string }
o.test();
~~~~
declare const test: (o:string) => void
test();
~~~~~~ a. If the call target is part of a property access expression, only the last name is part of the span (together with the arguments). declare const o: { test(o:string): void }
o.test();
~~~~~~ I think this is a nice improvement over #31414 and also improves error spans on long invocations chains where the offending call has a non-callable target (something #31414 did not do). I know @sandersn is also working in this area (#32092) hope this will not conflict with that too much. |
1. When calling a non-callable expression the error span is on the call target not on the whole call 2. When calling a method, the error for overload resolution now includes the arguments (this was previously regressed by microsoft#31414)
52897db
to
e4bca96
Compare
@typescript-bot pack this |
Heya @DanielRosenwasser, I've started to run the tarball bundle task on this PR at e4bca96. You can monitor the build here. It should now contribute to this PR's status checks. |
Hey @DanielRosenwasser, I've packed this into an installable tgz. You can install it for testing by referencing it in your
and then running |
Fixes #32013