Don't add completions from a discriminated union type when the discriminant doesn't match#24770
Merged
5 commits merged intoJul 4, 2018
Merged
Don't add completions from a discriminated union type when the discriminant doesn't match#247705 commits merged into
5 commits merged into
Conversation
…minant doesn't match
Contributor
|
@weswigham can you please reivew |
weswigham
approved these changes
Jun 27, 2018
Member
weswigham
left a comment
There was a problem hiding this comment.
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?
Author
|
@weswigham Please re-review |
weswigham
reviewed
Jun 28, 2018
| 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); |
Member
There was a problem hiding this comment.
Since you're in the checker now, I think you should probably use isIdenticalTo, or potentially isAssignableTo.
Member
There was a problem hiding this comment.
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).
This pull request was closed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #24763