Closed shicks closed 5 years ago
The proposed .d.ts for Array.prototype.flat is much less accurate than it could be.
Array.prototype.flat
The following is more in line with the implementation:
type Unwrap<X> = X extends (infer Y)[] ? Y : X; interface Array<T> { // ... flat(depth: 2): Unwrap<Unwrap<Unwrap<this>>>[]; flat(depth?: 1): Unwrap<Unwrap<this>>[]; flat(depth: 0): Unwrap<this>[]; flat(depth?: number): any[]; }
This allows correctly inferring that calling flat(1) on, e.g., (number | number[][])[] returns (number | number[])[].
(number | number[][])[]
(number | number[])[]
That file is no longer particularly relevant. (Nor is this repository, for that matter.) TypeScript has its own definitions, and any issues with them should be raised with the TypeScript team, not here.
The proposed .d.ts for
Array.prototype.flat
is much less accurate than it could be.The following is more in line with the implementation:
This allows correctly inferring that calling flat(1) on, e.g.,
(number | number[][])[]
returns(number | number[])[]
.