Typescript Turn Tuple Type to Array

Acid Coder
Jun 29, 2022

--

here is how you do it

type TupleToArray<
T extends unknown[],
Acc = never
> = T extends [infer H, ...infer Rest]
? Rest extends []
? (H | Acc)[]
: TupleToArray<Rest, Acc | H>
: "impossible route"
type A = TupleToArray<[number, string, boolean]> // (string | number | boolean)[]

playground

joke, I was messing, here is the easy way

type B = [number, string, boolean][number][] // (string | number | boolean)[]

--

--

Acid Coder

Typescript Zombie. Youtube Pikachu On Acid. (Unrelated to programming but by watching it you become a good developer overnight)