-
Notifications
You must be signed in to change notification settings - Fork 13k
Discard types that reduce to never
before discriminating by discriminable items
#62275
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
base: main
Are you sure you want to change the base?
Discard types that reduce to never
before discriminating by discriminable items
#62275
Conversation
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.
Pull Request Overview
This PR fixes an issue where TypeScript's type discrimination was not properly handling union types that reduce to never
. The fix ensures that types reducing to never
are discarded before performing discrimination by discriminable items.
- Adds a compiler test case demonstrating the fix for contextual typing by discriminable unions
- Updates the type checker to filter out types that reduce to
never
during discrimination - Includes baseline test files showing the expected type behavior
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
tests/cases/compiler/contextuallyTypedByDiscriminableUnion2.ts | New test case demonstrating the fix for discriminable union typing with never-reducing types |
tests/baselines/reference/contextuallyTypedByDiscriminableUnion2.types | Expected type output baseline for the new test case |
tests/baselines/reference/contextuallyTypedByDiscriminableUnion2.symbols | Expected symbol output baseline for the new test case |
src/compiler/checker.ts | Core fix that excludes never-reducing types during discrimination |
interface EnableA { | ||
readonly enableA: true; | ||
// this introduces a conflicting property with some of the other members of MyComponentProps | ||
// making relevant final union members reduced nevers |
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.
The comment should be more specific about which members have conflicting properties and how this leads to never types. Consider explaining the specific conflict between EnableA requiring enableB: true and DisableB requiring enableB: false.
// making relevant final union members reduced nevers | |
// This introduces a conflicting property: EnableA requires enableB: true, | |
// but DisableB requires enableB: false. As a result, any union member combining | |
// EnableA and DisableB is reduced to never, since enableB cannot be both true and false. |
Copilot uses AI. Check for mistakes.
interface EnableA { | ||
readonly enableA: true; | ||
// this introduces a conflicting property with some of the other members of MyComponentProps | ||
// making relevant final union members reduced nevers |
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 comment contains unclear language. 'reduced nevers' should be 'reduce to never' for grammatical correctness and clarity.
// making relevant final union members reduced nevers | |
// making relevant final union members reduce to never |
Copilot uses AI. Check for mistakes.
fixes #62256