Skip to content

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

Merged
5 commits merged into
masterfrom
completionsDiscriminatedUnion
Jul 4, 2018
Merged

Don't add completions from a discriminated union type when the discriminant doesn't match#24770
5 commits merged into
masterfrom
completionsDiscriminatedUnion

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented Jun 7, 2018

Fixes #24763

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

mhegazy commented Jun 7, 2018

@weswigham can you please reivew

Copy link
Copy Markdown
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
Copy Markdown
Author

ghost commented Jun 28, 2018

@weswigham Please re-review

Comment thread src/compiler/checker.ts Outdated
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
Copy Markdown
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
Copy Markdown
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
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants