Skip to content

Commit 816b704

Browse files
committed
Fix unsound Array.flatMap() typings
1 parent 7c14aff commit 816b704

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/lib/es2019.array.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ interface ReadonlyArray<T> {
1111
* thisArg is omitted, undefined is used as the this value.
1212
*/
1313
flatMap<U, This = undefined> (
14-
callback: (this: This, value: T, index: number, array: T[]) => U | ReadonlyArray<U>,
14+
callback: (this: This, value: T, index: number, array: T[]) => U,
1515
thisArg?: This
16-
): U[]
16+
): (U extends readonly (infer V)[] ? V : U)[];
1717

1818

1919
/**
@@ -125,9 +125,9 @@ interface Array<T> {
125125
* thisArg is omitted, undefined is used as the this value.
126126
*/
127127
flatMap<U, This = undefined> (
128-
callback: (this: This, value: T, index: number, array: T[]) => U | ReadonlyArray<U>,
128+
callback: (this: This, value: T, index: number, array: T[]) => U,
129129
thisArg?: This
130-
): U[]
130+
): (U extends readonly (infer V)[] ? V : U)[];
131131

132132
/**
133133
* Returns a new array with all sub-array elements concatenated into it recursively up to the

tests/baselines/reference/arrayFlatMap.types

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ const readonlyArray: ReadonlyArray<number> = [];
99

1010
array.flatMap((): ReadonlyArray<number> => []); // ok
1111
>array.flatMap((): ReadonlyArray<number> => []) : number[]
12-
>array.flatMap : <U, This = undefined>(callback: (this: This, value: number, index: number, array: number[]) => U | readonly U[], thisArg?: This) => U[]
12+
>array.flatMap : <U, This = undefined>(callback: (this: This, value: number, index: number, array: number[]) => U, thisArg?: This) => (U extends readonly (infer V)[] ? V : U)[]
1313
>array : number[]
14-
>flatMap : <U, This = undefined>(callback: (this: This, value: number, index: number, array: number[]) => U | readonly U[], thisArg?: This) => U[]
14+
>flatMap : <U, This = undefined>(callback: (this: This, value: number, index: number, array: number[]) => U, thisArg?: This) => (U extends readonly (infer V)[] ? V : U)[]
1515
>(): ReadonlyArray<number> => [] : () => readonly number[]
1616
>[] : undefined[]
1717

1818
readonlyArray.flatMap((): ReadonlyArray<number> => []); // ok
1919
>readonlyArray.flatMap((): ReadonlyArray<number> => []) : number[]
20-
>readonlyArray.flatMap : <U, This = undefined>(callback: (this: This, value: number, index: number, array: number[]) => U | readonly U[], thisArg?: This) => U[]
20+
>readonlyArray.flatMap : <U, This = undefined>(callback: (this: This, value: number, index: number, array: number[]) => U, thisArg?: This) => (U extends readonly (infer V)[] ? V : U)[]
2121
>readonlyArray : readonly number[]
22-
>flatMap : <U, This = undefined>(callback: (this: This, value: number, index: number, array: number[]) => U | readonly U[], thisArg?: This) => U[]
22+
>flatMap : <U, This = undefined>(callback: (this: This, value: number, index: number, array: number[]) => U, thisArg?: This) => (U extends readonly (infer V)[] ? V : U)[]
2323
>(): ReadonlyArray<number> => [] : () => readonly number[]
2424
>[] : undefined[]
2525

0 commit comments

Comments
 (0)