Tuple to Union
#
introductionImplement a generic TupleToUnion<T>
which covers the values of a tuple to its values union.
For example
ts
type Arr = ['1', '2', '3']const a: TupleToUnion<Arr> // expected to be '1' | '2' | '3'
View on GitHubts
type Arr = ['1', '2', '3']const a: TupleToUnion<Arr> // expected to be '1' | '2' | '3'
#
start pointtsTry
/* _____________ Your Code Here _____________ */ÂtypeTupleToUnion <T > = anyÂ/* _____________ Test Cases _____________ */typecases = [Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <TupleToUnion <[123, '456', true]>, 123 | '456' | true>>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <TupleToUnion <[123]>, 123>>,]
take the challengetsTry
/* _____________ Your Code Here _____________ */ÂtypeTupleToUnion <T > = anyÂ/* _____________ Test Cases _____________ */typecases = [Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <TupleToUnion <[123, '456', true]>, 123 | '456' | true>>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <TupleToUnion <[123]>, 123>>,]