Typescript类型体操 - Tuple To Union
题目
中文
实现泛型TupleToUnion<T>
,它返回元组所有值的合集。
例如
type Arr = ['1', '2', '3']
type Test = TupleToUnion<Arr> // expected to be '1' | '2' | '3'
English
Implement a generic TupleToUnion<T>
which covers the values of a tuple to its values union.
For example
type Arr = ['1', '2', '3']
type Test = TupleToUnion<Arr> // expected to be '1' | '2' | '3'
答案
type TupleToUnion<T extends unknown[]> = T[number]