// Basic level 1 values of a typetypeLevel1<Textendsany[]>=T[number];// Level 2 making use of level 1 twicetypeLevel2<Textendsany[]>=Level1<Level1<T>>;typeNaiveFlat<Textendsany[]>=Level2<T>;typeNaive=[['a'],['b','c'],['d']];typeNaiveTestResult=Assert<NaiveFlat<Naive>,"a"|"b"|"c"|"d">;// should be true
Deep version-
// Recursive mapped type for nested leveltypeNestedLevel<Textendsany[]>={[KinkeyofT]:T[K]extendsany[]?NestedLevel<T[K]>:T[K];}[number];typeDeepFlat<Textendsany[]>=NestedLevel<T>;typeDeep=[['a'],['b','c'],[['d']],[[[['e']]]]];typeDeepTestResult=Assert<DeepFlat<Deep>,"a"|"b"|"c"|"d"|"e">// should be true
I am Software Developer, currently interested in static type languages (TypeScript, Elm, ReScript) mostly in the frontend land, but working actively in Python also. I am available for mentoring.
This time, after a lot of thought & attempts :P
Naive version -
Deep version-
Playground link
Nice but the solution can be simpler 😉
Yeah, realised it later. Updated the answer :)