Skip to content

Stack overflow when spread a tuple type alias inside itself (with conditional type and generic default) #25291

@HerringtonDarkholme

Description

@HerringtonDarkholme

TypeScript Version: Version 3.0.0-dev.20180628

Search Terms: tuple types

Code

type PromisedTuple<L extends any[], U = (...args: L) => void> =
    U extends (h: infer H, ...args: infer R) ? [Promise<H>, ...PromisedTuple<R>] : []

type Promised = PromisedTuple<[1, 2, 3]> 
// expect [Promise<1>, Promise<2>, Promise<3>]

Expected behavior:
Either produce type in comment above, or produce a compile error.

Actual behavior:

RangeError: Maximum call stack size exceeded at getTypeFromTypeNode

Related Issues: #24897 (comment)

Extended explanation:

This code tries to model the Array#map on a heterogeneous tuple type . It uses conditional type and generic default to work around recursion.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions