Skip to content

Don't add completions from a discriminated union type when the discriminant doesn't match #24770

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

Merged
5 commits merged into from
Jul 4, 2018

Conversation

ghost
Copy link

@ghost ghost commented Jun 7, 2018

Fixes #24763

@mhegazy mhegazy requested a review from weswigham June 7, 2018 22:44
@mhegazy
Copy link
Contributor

mhegazy commented Jun 7, 2018

@weswigham can you please reivew

Copy link
Member

@weswigham weswigham left a comment

Choose a reason for hiding this comment

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

This is OK.... but maybe we should just expose the logic for discriminating a union type by the type of one of its fields and another type from the checker?

@ghost
Copy link
Author

ghost commented Jun 28, 2018

@weswigham Please re-review

if (expected && typeIsLiteralType(expected)) {
const actual = getTypeOfNode(property);
// Apparently two literal types for the same literal are still not equal.
return !!actual && (!typeIsLiteralType(actual) || actual.value !== expected.value);
Copy link
Member

Choose a reason for hiding this comment

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

Since you're in the checker now, I think you should probably use isIdenticalTo, or potentially isAssignableTo.

Copy link
Member

Choose a reason for hiding this comment

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

Alternatively, findMatchingDiscriminantType might be useful if you move all the filtering logic into the checker. Although it may be less flexible than you want, since it only selects exactly one type and not many (although, if you're trying to match normal discrimination behavior, that's where it is).

@ghost ghost merged commit 204b70d into master Jul 4, 2018
@ghost ghost deleted the completionsDiscriminatedUnion branch July 4, 2018 00:05
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants