题目
中文
实现泛型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]
标签:Typescript,Tuple,Union,TupleToUnion,Test,type
From: https://www.cnblogs.com/laggage/p/type-challenge-tuple-to-union.html