pengzhanbo
130字小于1分钟
2022-12-01
题目
Github: Tuple to union
实现泛型TupleToUnion<T>
,它返回元组所有值的合集。
type Arr = ['1', '2', '3']
type Test = TupleToUnion<Arr> // expected to be '1' | '2' | '3'
知识点
在访问元组的成员时,可以通过 [number]
索引,访问一个 由元组所有成员构成的联合类型。
type TupleToUnion<T extends any[]> = T[number]