Hi folks! ✋ Today we will play a bit with mapped types. The exercise is about getting all value types from the tuple type. Question will be slightly different (as I am still playing with the series format) and will be split into two tasks with different difficulty level.
type NaiveFlat<T extends any> = unknown // 🔥 here your code // test case type Naive = [['a'], ['b', 'c'], ['d']]; type NaiveResult = NaiveFlat<[['a'], ['b', 'c'], ['d']]> // should evaluate to "a" | "b" | "c" | "d"
Our goal is to make type level function
NaiveFlat which will take nested tuple and get all value types from it. Naive implementation should work with 1 level of nesting so tuple of tuples.
type DeepFlat<T extends any> = unknown // 🔥 here your code // test case type Deep = [['a'], ['b', 'c'], [['d']], [[[['e']]]]]; type DeepTestResult = DeepFlat<Deep> // should evaluate to "a" | "b" | "c" | "d" | "e"
We go level up. Deep version should flat any level of nested tuples.
The questions and ready to start code is available in The Playground
Post your answers in comments. Have fun! Answer will be published soon!
BTW please share your opinion if such questions with few options works for you? I want to know what you think about such format, thanks!