Skip to content

Port #62275: Discard types that reduce to never before discriminating by discriminable items#2749

Merged
jakebailey merged 2 commits intomainfrom
copilot/port-discard-never-types
Feb 12, 2026
Merged

Port #62275: Discard types that reduce to never before discriminating by discriminable items#2749
jakebailey merged 2 commits intomainfrom
copilot/port-discard-never-types

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 11, 2026

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 to any.

  • Filter out never-reducing types alongside primitives in discriminateTypeByDiscriminableItems:
// Before
if t.flags&TypeFlagsPrimitive == 0 {

// After
if t.flags&TypeFlagsPrimitive == 0 && c.getReducedType(t).flags&TypeFlagsNever == 0 {

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…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
Copilot AI requested a review from jakebailey February 11, 2026 00:22
@jakebailey jakebailey marked this pull request as ready for review February 11, 2026 00:59
Copilot AI review requested due to automatic review settings February 11, 2026 00:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 never when initializing the candidate set in discriminateTypeByDiscriminableItems.
  • Update reference baselines to reflect correct contextual typing (notably, setItem’s parameter no longer falls back to any) 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.

@jakebailey jakebailey enabled auto-merge February 11, 2026 01:33
@jakebailey jakebailey added this pull request to the merge queue Feb 12, 2026
Merged via the queue into main with commit 380275c Feb 12, 2026
41 of 43 checks passed
@jakebailey jakebailey deleted the copilot/port-discard-never-types branch February 12, 2026 17:21
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants