Skip to content

Fix union type error reporting in getIterationTypesOfIterable#2768

Closed
Copilot wants to merge 3 commits intomainfrom
copilot/fix-regexp-indices-error
Closed

Fix union type error reporting in getIterationTypesOfIterable#2768
Copilot wants to merge 3 commits intomainfrom
copilot/fix-regexp-indices-error

Conversation

Copy link
Contributor

Copilot AI commented Feb 12, 2026

When checking iterability of union types, errors were reported on individual non-iterable constituents (e.g., Type 'undefined') instead of the full union type (e.g., Type '[number, number] | undefined'), diverging from TypeScript's behavior.

declare let indices: RegExpIndicesArray; // extends Array<[number, number] | undefined>
let [[x, y]] = indices;
// Before: error TS2488: Type 'undefined' must have a '[Symbol.iterator]()' method...
// After:  error TS2488: Type '[number, number] | undefined' must have a '[Symbol.iterator]()' method...

Changes

  • Move union handling from getIterationTypesOfIterableWorker to getIterationTypesOfIterable — TypeScript handles union iteration types in the outer function, iterating over constituents and failing the entire resolution if any constituent is non-iterable. The Go port was handling unions in the worker, which reported errors per-constituent and combined partial results instead of failing.
  • Add compiler test regExpIndicesArrayDestructuring.ts covering the reported case.
  • Delete 7 submodule diff files — existing baselines for ES5For-ofTypeCheck7, ES5For-ofTypeCheck9, ES5For-of30, noImplicitAnyLoopCrash, and destructuringArrayBindingPatternAndAssignment4 now match TypeScript exactly.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • tsplay.dev
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Spreading variable of RegExpIndicesArray type will cause error</issue_title>
<issue_description>## Steps to reproduce

  1. Start a plain new project, with @typescript/native-preview@npm:7.0.0-dev.20260211.1 as dependency.
  2. Run npx tsgo --init to get the default tsconfig.
  3. Add a src/main.ts & run npx tsgo --noEmit.
// src/main.ts

declare let indices: RegExpIndicesArray;
let [[x, y]] = indices;

Behavior with typescript@6.0

No error, as it should be. See https://tsplay.dev/mqb9ZW.

Behavior with tsgo

src/main.ts:4:6 - error TS2488: Type 'undefined' must have a '[Symbol.iterator]()' method that returns an iterator.

4 let [[x, y]] = indices;
       ~~


Found 1 error in src/main.ts:4

Note: The error is the same as if indices is of type indices | undefined. It seems only happen to RegExpIndicesArray, so I wonder if it is the case that tsgo cannot infer extended array element type correctly during spreading.</issue_description>

<agent_instructions>Make a compiler test for this issue first and commit it and its baselines, then look into the problem </agent_instructions>

Comments on the Issue (you are @copilot in this section)


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

Copilot AI and others added 2 commits February 12, 2026 08:41
…error reporting

Move union type handling from getIterationTypesOfIterableWorker to
getIterationTypesOfIterable to match TypeScript's behavior. This ensures
that when any constituent of a union type is not iterable, the error is
reported on the full union type (e.g., '[number, number] | undefined')
rather than the individual non-iterable constituent (e.g., 'undefined').

Also ensures that when any constituent fails, the entire iteration type
resolution fails (matching TypeScript's behavior of returning undefined
for the whole union).

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
…nion types

Multiple diff files deleted as tsgo output now matches TypeScript exactly:
- ES5For-ofTypeCheck7, ES5For-ofTypeCheck9, ES5For-of30
- noImplicitAnyLoopCrash
- destructuringArrayBindingPatternAndAssignment4 (types diff removed)

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix error caused by spreading RegExpIndicesArray Fix union type error reporting in getIterationTypesOfIterable Feb 12, 2026
Copilot AI requested a review from jakebailey February 12, 2026 08:54
@jakebailey jakebailey closed this Feb 14, 2026
@jakebailey jakebailey deleted the copilot/fix-regexp-indices-error branch February 14, 2026 23:57
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.

Spreading variable of RegExpIndicesArray type will cause error

2 participants