export type NestedArrayValue < V > = V | NestedArray < V > ; export interface NestedArray < T > extends Array < NestedArrayValue < T > > { } function hasSubArray ( a ) { return a . some ( i => Array . isArray ( i ) ) ; } param array export function flatten < T > ( array ) { if ( ! hasSubArray ( array ) ) { return < T [ ] > array ; } else { let acc = new Array < T > ( ) ; for ( let val of array ) { if ( Array . isArray ( val ) ) { acc = acc . concat ( flatten ( val ) ) ; } else { acc . push ( val ) ; } } return acc ; } }