Acid Coder

In the last post we know multiplication is possible

In this post we are going to try division

type CreateArrayWithLengthX<
LENGTH extends number,
ACC extends unknown[] = [],
> = ACC['length'] extends LENGTH
? ACC
: CreateArrayWithLengthX<LENGTH, [...ACC,1]>
type Division<Dividend extends number, Divisor extends number, ACC extends unknown[] = []…

--

--

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)[]

--

--