Skip to content

Type checker hangs on recursive type with arrays #41771

Closed
@judofyr

Description

@judofyr

TypeScript Version: 4.1.2

Search Terms:

Code

type BuildTuple<L extends number, T extends any[] = [any]> = 
    T['length'] extends L ? T : BuildTuple<L, [...T, ...T]>;

type A = BuildTuple<3>

Expected behavior:

The type checker completes in a reasonable time, either by succeeding or by reporting "Type instantiation is excessively deep and possibly infinite".

Actual behavior:

The type checker just hangs.

Playground Link:

https://www.typescriptlang.org/play?ts=4.1.2#code/C4TwDgpgBAQgrgSwDYBMAqcxIgHgDJQQAewEAdigM5RlwC2ARhAE4A0UahJ5VUAhmRABtALpQAvFCECQIgHwSoAKCiqOQgOTYyAc2AALDWOKkK1AgH4OUAFyxEqDFlx52QgHSe07T+7TyAbiUlUEgoAEFFeGR0TGwcAGY5JSA

Metadata

Metadata

Assignees

Labels

Breaking ChangeWould introduce errors in existing codeBugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions