ghaiklor / type-challenges-solutions

Solutions for the collection of TypeScript type challenges with explanations
https://ghaiklor.github.io/type-challenges-solutions/
Creative Commons Attribution 4.0 International
470 stars 56 forks source link

type-challenges-solutions/ru/medium-flatten #128

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

Flatten

This project is aimed at helping you better understand how the type system works, writing your own utilities, or just having fun with the challenges.

https://ghaiklor.github.io/type-challenges-solutions/ru/medium-flatten.html

bini1988 commented 2 years ago
type Flatten<T extends any[], A extends any[] = []> = T extends [infer H, ...infer L] 
    ? Flatten<L, H extends any[] ? [...A, ...Flatten<H>] : [...A, H]>  : A;