shaKY-iota / type-challenges

Collection of TypeScript type challenges with online judge
https://tsch.js.org/
MIT License
0 stars 0 forks source link

459 - Flatten #23

Open shaKY-iota opened 2 years ago

shaKY-iota commented 2 years ago
// your answers
type Flatten<T extends unknown[], U extends unknown[] = []> = T extends [infer First, ...infer Rest] ? First extends unknown[] ? Flatten<[...First, ...Rest], U> : Flatten<Rest, [...U, First]> : U
shaKY-iota commented 2 years ago

https://github.com/type-challenges/type-challenges/issues/593#issue-777632788

type Flatten<T extends unknown[]> = T extends [infer First, ...infer Rest] ? First extends unknown[] ? Flatten<[...First, ...Rest]> : [First, ...Flatten<Rest>] : T