type ArrayFlat<T> = T extends ReadonlyArray ? _IfNotAnyOrNever<T, _ArrayFlat<T>> : never;Type that flattens a nested Array structure into a single Array.
If an element is an Array, it will recursively flatten it until no Array remains.
| Type Parameter | Description |
|---|---|
|
|
The |
A flattened version of the given Array type.
// [0, 1, 2, 3, 4, 5, 6, 7]
type Flattened1 = ArrayFlat<[0, 1, [2, 3, [4, 5, [6, 7[]]]]]>;
// (0 | 1 | 2 | 3 | 4 | 5 | 6 | 7)[]
type Flattened2 = ArrayFlat<(0 | 1 | [2] | [3] | [[4]] | [[5]] | [[[6]]] | [[[7[]]]])[]>;
// never
type Never = ArrayFlat<any>;