- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
// @strict: true
// @lib: es2020
// @declaration: true
type BadFlatArray<Arr, Depth extends number> = {
obj: {
"done": Arr,
"recur": Arr extends ReadonlyArray<infer InnerArr>
? BadFlatArray<InnerArr, [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20][Depth]>
: Arr
}[Depth extends -1 ? "done" : "recur"]
}["obj"];
declare function flat<A, D extends number = 1>(
arr: A,
depth?: D
): BadFlatArray<A, D>[]
function foo<T>(arr: T[], depth: number) {
return flat(arr, depth);
}
function main() {
foo<number>([1.0, 2.0], 2);
}