Skip to content

Hide function type missing props if return and target type same. #36746

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

Closed
wants to merge 1 commit into from

Conversation

openorclose
Copy link

@openorclose openorclose commented Feb 12, 2020

Fixes #35735.

Whenever we find a source function type whose return type matches the target type, we only produce the error message "did you mean to call this expression" without checking their properties.

As mentioned in the linked issue, this should provide a more relevant error message.

@msftclas
Copy link

msftclas commented Feb 12, 2020

CLA assistant check
All CLA requirements met.

@openorclose openorclose changed the title Hide function type missing props if return and target time same. Hide function type missing props if return and target type same. Feb 12, 2020
@openorclose
Copy link
Author

Not sure why the reviewers list isn't loading, @DanielRosenwasser hope you can take a look!

@sandersn sandersn added the For Backlog Bug PRs that fix a backlog bug label Feb 20, 2020
@sandersn
Copy link
Member

@DanielRosenwasser you are probably interested in this as well.

Copy link
Member

@amcasey amcasey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay in getting back to you. This seems like a great change, but I have some (probably ignorant) questions before we go ahead.

@@ -14074,8 +14074,8 @@ namespace ts {
source: Type,
target: Type,
relation: Map<RelationComparisonResult>,
headMessage: DiagnosticMessage | undefined,
containingMessageChain: (() => DiagnosticMessageChain | undefined) | undefined,
_headMessage: DiagnosticMessage | undefined,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these parameters are unused, personally, I'd remove them.

addRelatedInfo(diagnostic, createDiagnosticForNode(
node,
signatures === constructSignatures ? Diagnostics.Did_you_mean_to_use_new_with_this_expression : Diagnostics.Did_you_mean_to_call_this_expression
));
if (errorOutputContainer && errorOutputContainer.skipLogging) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really familiar with errorOutputContainer, but it sort of looks like this should have an else case that adds the diagnostic to diagnostics instead. @sandersn should be able to confirm.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the else clause, you'd add the diagnostic to the headMessage or containingMessageChain, which is was checkTypeAssignableTo does. The logic there is somewhat complicated so I'm not sure it's a good idea to replicate it here either. You still need to call checkTypeAssignableTo.

@@ -1,8 +1,6 @@
tests/cases/conformance/jsx/file.tsx(24,28): error TS2551: Property 'NAme' does not exist on type 'IUser'. Did you mean 'Name'?
tests/cases/conformance/jsx/file.tsx(36,15): error TS2322: Type '(user: IUser) => Element' is not assignable to type 'string | number | boolean | any[] | ReactElement<any>'.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't there supposed to be some new text about "did you mean to call?"? Or does that not apply in this case?

Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replacing the call to checkTypeAssignableTo with your own error in elaborateDidYouMeanToCallOrConstruct is not sufficient. That function basically just tags a "Did you mean" error on to the end of the real error.

Instead, you'll need to change the behaviour of signatures in structuredTypeRelatedTo, probably to special-case them either in propertiesRelatedTo or signaturesRelatedTo, or some third code path.

addRelatedInfo(diagnostic, createDiagnosticForNode(
node,
signatures === constructSignatures ? Diagnostics.Did_you_mean_to_use_new_with_this_expression : Diagnostics.Did_you_mean_to_call_this_expression
));
if (errorOutputContainer && errorOutputContainer.skipLogging) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the else clause, you'd add the diagnostic to the headMessage or containingMessageChain, which is was checkTypeAssignableTo does. The logic there is somewhat complicated so I'm not sure it's a good idea to replicate it here either. You still need to call checkTypeAssignableTo.

@sandersn
Copy link
Member

This PR hasn't seen any activity for quite a while, so I'm going to close it to keep the number of open PRs manageable. Feel free to open a fresh PR or continue the discussion here.

@sandersn sandersn closed this Mar 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Avoid listing missing properties on types with only call/construct signatures
4 participants