Skip to content

Port TypeScript PR #62661: fix [Symbol.iterator]() lost on union with never - #2737

Merged
Jake Bailey (jakebailey) merged 2 commits into
mainfrom
copilot/fix-symbol-iterator-union-never
Feb 10, 2026
Merged

Port TypeScript PR #62661: fix [Symbol.iterator]() lost on union with never#2737
Jake Bailey (jakebailey) merged 2 commits into
mainfrom
copilot/fix-symbol-iterator-union-never

Conversation

Copilot AI commented Feb 10, 2026

Copy link
Copy Markdown
Contributor

Ports microsoft/TypeScript#62661.

getIterationTypesOfIterable wasn't calling getReducedType, so non-iterable types reducible to never (e.g. { t: "a" } & { t: "b" }) weren't being erased from unions before iteration checking. This caused [Symbol.iterator]() to be "lost":

declare var x: number[] | ({ t: "a" } & { t: "b" });
let [el2] = x; // incorrectly errored with TS2488
for (const elem of x) {} // incorrectly errored with TS2488
  • Add t = c.getReducedType(t) at the top of getIterationTypesOfIterable in internal/checker/checker.go
  • Baseline diff for iterableWithNeverAsUnionMember deleted — output now matches upstream

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

… never

Add getReducedType() call at the start of getIterationTypesOfIterable
so non-iterable types reducible to never are properly erased from unions.

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix Symbol.iterator lost on union with never Port TypeScript PR #62661: fix [Symbol.iterator]() lost on union with never Feb 10, 2026
@jakebailey
Jake Bailey (jakebailey) marked this pull request as ready for review February 10, 2026 23:12
Copilot AI review requested due to automatic review settings February 10, 2026 23:12

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.

Pull request overview

This PR ports TypeScript PR #62661, which fixes a bug where [Symbol.iterator]() was incorrectly reported as missing on union types containing never-reducible intersections (e.g., number[] | ({ t: "a" } & { t: "b" })). The fix adds a single line to reduce types before iteration checking, ensuring that impossible intersections are eliminated from unions before checking for iterator methods.

Changes:

  • Add getReducedType call in getIterationTypesOfIterable to reduce types before iteration checking
  • Eliminate baseline diff file for iterableWithNeverAsUnionMember test, indicating convergence with upstream TypeScript behavior

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
internal/checker/checker.go Added t = c.getReducedType(t) at the start of getIterationTypesOfIterable to reduce never-intersections before iteration checking
testdata/baselines/reference/submodule/compiler/iterableWithNeverAsUnionMember(target=esnext).errors.txt.diff Removed diff file (now empty), indicating the port now matches upstream behavior
testdata/baselines/reference/submodule/compiler/iterableWithNeverAsUnionMember(target=esnext).errors.txt Updated baseline showing 3 errors instead of 6 (3 spurious errors eliminated)

@jakebailey
Jake Bailey (jakebailey) added this pull request to the merge queue Feb 10, 2026
Merged via the queue into main with commit 2fca172 Feb 10, 2026
26 checks passed
@jakebailey
Jake Bailey (jakebailey) deleted the copilot/fix-symbol-iterator-union-never branch February 10, 2026 23:50
Copilot AI added a commit that referenced this pull request Feb 25, 2026
… never (#2737)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Jake Bailey (jakebailey) added a commit to jakebailey/TypeScript that referenced this pull request Aug 13, 2026
…r]() lost on union with never (microsoft/typescript-go#2737)

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