Skip to content

Variables declared in array destructuring patterns can't be used in initializers of other variables in the same pattern #33257

Closed
@thorn0

Description

@thorn0

TypeScript Version: 3.6.2

Search Terms: circular reference, array destructuring initializer

Code

// @strict
declare const x: number | undefined;
const [a, b = a] = [10, x];

Expected behavior: Should compile. Both a and b are of type number.

Actual behavior:
Error: 'a' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

Playground Link: playground

Related Issues: #32950, #33191

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptHas ReproThis issue has compiler-backed repros: https://aka.ms/ts-repros

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions