題目
中文
構造一個給定長度的元組。
例如
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]>;