Skip to content

Preserve widening literals when narrowing primitive unions by equality - #64771

Open
Mateusz Burzyński (Andarist) wants to merge 1 commit into
microsoft:mainfrom
Andarist:andarist/fix-equality-narrowing-widening-literals
Open

Mateusz Burzyński (Andarist) wants to merge 1 commit into
microsoft:mainfrom
Andarist:andarist/fix-equality-narrowing-widening-literals

Conversation

@Andarist

Copy link
Copy Markdown
Contributor

fixes #64766

Copilot AI balanced review requested due to automatic review settings October 13, 2026 14:47
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Oct 13, 2026
@typescript-automation typescript-automation Bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Oct 13, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The targeted fix matches the previous general-path behavior and is covered by focused regression and negative-control tests.

0 open findings

What changed in this PR

Fixes equality narrowing so primitive unions retain widening literal freshness while explicit literal unions remain non-widening.

Changes:

  • Distinguishes exact literal constituents from primitive containment.
  • Adds regression coverage for strings, numbers, bigints, mutable inference, and flatMap.
File Description
tsc/​internal/​checker/​flow.go Preserves literal freshness during equality narrowing.
tsc/​testdata/​tests/​cases/​compiler/​narrowingByEqualityPreservesWideningLiterals.ts Adds regression and control cases.
tsc/​testdata/​baselines/​reference/​compiler/​narrowingByEqualityPreservesWideningLiterals.types Records inferred types.
tsc/​testdata/​baselines/​reference/​compiler/​narrowingByEqualityPreservesWideningLiterals.symbols Records resolved symbols.
tsc/​testdata/​baselines/​reference/​compiler/​narrowingByEqualityPreservesWideningLiterals.errors.txt Records expected control-case diagnostics.

🧠 Review effort: Balanced


💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@typescript-automation typescript-automation Bot added For Milestone Bug PRs that fix a bug with a specific milestone and removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Oct 13, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Milestone Bug PRs that fix a bug with a specific milestone

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

=== narrowing of a primitive union now produces a non-widening literal type (regression from microsoft/typescript-go#4781)

2 participants