@scayle/storefront-core
Version:
Collection of essential utilities to work with the Storefront API
18 lines (17 loc) • 721 B
TypeScript
/**
* Recursive helper type to extract the innermost non-array element types from T.
* Handles nested arrays and unions of arrays/non-arrays.
*/
type FlattenElement<T> = T extends ReadonlyArray<infer U> ? FlattenElement<U> : T;
/**
* Flattens an array of arrays with unknown depth into a single-level array.
*
* @template T The type of the potentially nested array. Must extend `readonly unknown[]`.
*
* @param array The array to flatten.
*
* @returns A new, single-level array containing all the innermost elements
* extracted from the input array. The element type is inferred recursively.
*/
export declare const flattenDeep: <T extends ReadonlyArray<unknown>>(array: T) => FlattenElement<T>[];
export {};