Port #62275: Discard types that reduce to never before discriminating by discriminable items#2749
Merged
jakebailey merged 2 commits intomainfrom Feb 12, 2026
Merged
Conversation
…discriminating by discriminable items Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Port discard types that reduce to never before discriminating
Port #62275: Discard types that reduce to never before discriminating by discriminable items
Feb 11, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Ports TypeScript PR microsoft/TypeScript#62275 to improve contextual typing and discriminant-based narrowing by ensuring union constituents that reduce to never don’t participate in discriminateTypeByDiscriminableItems, preventing erroneous narrowing that could degrade contextual typing to any.
Changes:
- Exclude union constituents whose reduced type is
neverwhen initializing the candidate set indiscriminateTypeByDiscriminableItems. - Update reference baselines to reflect correct contextual typing (notably,
setItem’s parameter no longer falls back toany) and removal of the prior TS7006 error in the referenced test.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
internal/checker/relater.go |
Filters out constituents that reduce to never before discriminant-based narrowing. |
testdata/baselines/reference/submodule/compiler/contextuallyTypedByDiscriminableUnion2.types.diff |
Updates diff baseline to reflect reduced mismatch after the fix. |
testdata/baselines/reference/submodule/compiler/contextuallyTypedByDiscriminableUnion2.types |
Updates reference .types output showing improved contextual typing (no any fallback). |
testdata/baselines/reference/submodule/compiler/contextuallyTypedByDiscriminableUnion2.errors.txt.diff |
Removes prior error diff content associated with TS7006. |
testdata/baselines/reference/submodule/compiler/contextuallyTypedByDiscriminableUnion2.errors.txt |
Removes the previously expected TS7006 error output. |
RyanCavanaugh
approved these changes
Feb 12, 2026
Copilot AI
added a commit
that referenced
this pull request
Feb 25, 2026
… by discriminable items (#2749) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Ports microsoft/TypeScript#62275.
Intersection types that reduce to
never(e.g., conflicting properties like{ enableB: true } & { enableB: false }) were participating in discriminant-based narrowing, preventing proper contextual typing and causing parameters to fall back toany.discriminateTypeByDiscriminableItems:💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.