-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Conversation
…minant doesn't match
@weswigham can you please reivew |
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.
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?
@weswigham Please re-review |
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); |
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.
Since you're in the checker now, I think you should probably use isIdenticalTo
, or potentially isAssignableTo
.
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.
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).
Fixes #24763