镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Mapped types on tuples and arrays not working recursively #29442

Description

TypeScript Version: 3.2.2 (ts playground)

Search Terms: recursive, mapped types, tuple, array

Code

type DeepMap<T extends unknown[], R> = {
  [K in keyof T]: T[K] extends unknown[] ? DeepMap<T[K], R> : R;
};

type tup = [string, [string, [string]]];
type arr = string[][];

type t1 = DeepMap<tup, number>;
type t2 = DeepMap<arr, number>;

Expected behavior:

type t1 = [number, [number, [number]]];
type t2 = number[][];

Actual behavior:

type t1 = [number, any];
type t2 = any[];

Playground Link:

Related Issues:

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

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