Skip to content

Spreading variable of RegExpIndicesArray type will cause error #2767

@hkleungai

Description

@hkleungai

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.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions