Typescript类型体操 - ConstructTuple
题目
中文
构造一个给定长度的元组。
例如
type result = ConstructTuple<2> // 期望得到 [unknown, unkonwn]
English
Construct a tuple with a given length.
For example
type result = ConstructTuple<2> // expect to be [unknown, unkonwn]
答案
type ConstructTuple<
L extends number,
K extends any[] = []
> = K['length'] extends L ? K : ConstructTuple<L, [unknown, ...K]>;