// Adapted from https://github.com/microsoft/TypeScript/blob/master/lib/lib.es2019.array.d.ts interface ReadonlyArray { /** * Returns a new array with all sub-array elements concatenated into it recursively up to the * specified depth. * * @param depth The maximum recursion depth */ flat( this: | readonly U[][][][][] | ReadonlyArray | ReadonlyArray> | ReadonlyArray>> | ReadonlyArray>>> | ReadonlyArray> | ReadonlyArray>>> | ReadonlyArray>>> | ReadonlyArray>>> | ReadonlyArray>> | ReadonlyArray>> | ReadonlyArray>> | ReadonlyArray>>> | ReadonlyArray>>> | ReadonlyArray>>> | ReadonlyArray>>>, depth: 4, ): U[]; /** * Returns a new array with all sub-array elements concatenated into it recursively up to the * specified depth. * * @param depth The maximum recursion depth */ flat( this: | readonly U[][][][] | ReadonlyArray>> | ReadonlyArray> | ReadonlyArray | ReadonlyArray> | ReadonlyArray>> | ReadonlyArray>> | ReadonlyArray>>, depth: 3, ): U[]; /** * Returns a new array with all sub-array elements concatenated into it recursively up to the * specified depth. * * @param depth The maximum recursion depth */ flat( this: | readonly U[][][] | ReadonlyArray | ReadonlyArray> | ReadonlyArray>, depth: 2, ): U[]; /** * Returns a new array with all sub-array elements concatenated into it recursively up to the * specified depth. * * @param depth The maximum recursion depth */ flat(this: readonly U[][] | ReadonlyArray, depth?: 1): U[]; /** * Returns a new array with all sub-array elements concatenated into it recursively up to the * specified depth. * * @param depth The maximum recursion depth */ flat(this: readonly U[], depth: 0): U[]; /** * Returns a new array with all sub-array elements concatenated into it recursively up to the * specified depth. If no depth is provided, flat method defaults to the depth of 1. * * @param depth The maximum recursion depth */ flat(depth?: number): any[]; } interface Array { /** * Returns a new array with all sub-array elements concatenated into it recursively up to the * specified depth. * * @param depth The maximum recursion depth */ flat(this: U[][][][][][][][], depth: 7): U[]; /** * Returns a new array with all sub-array elements concatenated into it recursively up to the * specified depth. * * @param depth The maximum recursion depth */ flat(this: U[][][][][][][], depth: 6): U[]; /** * Returns a new array with all sub-array elements concatenated into it recursively up to the * specified depth. * * @param depth The maximum recursion depth */ flat(this: U[][][][][][], depth: 5): U[]; /** * Returns a new array with all sub-array elements concatenated into it recursively up to the * specified depth. * * @param depth The maximum recursion depth */ flat(this: U[][][][][], depth: 4): U[]; /** * Returns a new array with all sub-array elements concatenated into it recursively up to the * specified depth. * * @param depth The maximum recursion depth */ flat(this: U[][][][], depth: 3): U[]; /** * Returns a new array with all sub-array elements concatenated into it recursively up to the * specified depth. * * @param depth The maximum recursion depth */ flat(this: U[][][], depth: 2): U[]; /** * Returns a new array with all sub-array elements concatenated into it recursively up to the * specified depth. * * @param depth The maximum recursion depth */ flat(this: U[][], depth?: 1): U[]; /** * Returns a new array with all sub-array elements concatenated into it recursively up to the * specified depth. * * @param depth The maximum recursion depth */ flat(this: U[], depth: 0): U[]; /** * Returns a new array with all sub-array elements concatenated into it recursively up to the * specified depth. If no depth is provided, flat method defaults to the depth of 1. * * @param depth The maximum recursion depth */ flat(depth?: number): any[]; }