Skip to content

Commit c68e334

Browse files
committed
Add tests
1 parent 82959b2 commit c68e334

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

tests/baselines/reference/arrayFlatMap.js

+8
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,18 @@ const array: number[] = [];
33
const readonlyArray: ReadonlyArray<number> = [];
44
array.flatMap((): ReadonlyArray<number> => []); // ok
55
readonlyArray.flatMap((): ReadonlyArray<number> => []); // ok
6+
7+
// #19535
8+
9+
declare function f(): number[] | number[][];
10+
const [x] = [1].flatMap(f);
11+
x == 1;
612

713

814
//// [arrayFlatMap.js]
915
var array = [];
1016
var readonlyArray = [];
1117
array.flatMap(function () { return []; }); // ok
1218
readonlyArray.flatMap(function () { return []; }); // ok
19+
var x = [1].flatMap(f)[0];
20+
x == 1;

tests/baselines/reference/arrayFlatMap.symbols

+14
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,17 @@ readonlyArray.flatMap((): ReadonlyArray<number> => []); // ok
1818
>flatMap : Symbol(ReadonlyArray.flatMap, Decl(lib.es2019.array.d.ts, --, --))
1919
>ReadonlyArray : Symbol(ReadonlyArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2016.array.include.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --))
2020

21+
// #19535
22+
23+
declare function f(): number[] | number[][];
24+
>f : Symbol(f, Decl(arrayFlatMap.ts, 3, 55))
25+
26+
const [x] = [1].flatMap(f);
27+
>x : Symbol(x, Decl(arrayFlatMap.ts, 8, 7))
28+
>[1].flatMap : Symbol(Array.flatMap, Decl(lib.es2019.array.d.ts, --, --))
29+
>flatMap : Symbol(Array.flatMap, Decl(lib.es2019.array.d.ts, --, --))
30+
>f : Symbol(f, Decl(arrayFlatMap.ts, 3, 55))
31+
32+
x == 1;
33+
>x : Symbol(x, Decl(arrayFlatMap.ts, 8, 7))
34+

tests/baselines/reference/arrayFlatMap.types

+19
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,22 @@ readonlyArray.flatMap((): ReadonlyArray<number> => []); // ok
2323
>(): ReadonlyArray<number> => [] : () => readonly number[]
2424
>[] : undefined[]
2525

26+
// #19535
27+
28+
declare function f(): number[] | number[][];
29+
>f : () => number[] | number[][]
30+
31+
const [x] = [1].flatMap(f);
32+
>x : number | number[]
33+
>[1].flatMap(f) : (number | number[])[]
34+
>[1].flatMap : <U, This = undefined, That extends number[]>(this: readonly number[], callback: (this: This, value: That[number], index: number, array: That) => U, thisArg?: This) => (U extends readonly (infer V)[] ? V : U)[]
35+
>[1] : number[]
36+
>1 : 1
37+
>flatMap : <U, This = undefined, That extends number[]>(this: readonly number[], callback: (this: This, value: That[number], index: number, array: That) => U, thisArg?: This) => (U extends readonly (infer V)[] ? V : U)[]
38+
>f : () => number[] | number[][]
39+
40+
x == 1;
41+
>x == 1 : boolean
42+
>x : number | number[]
43+
>1 : 1
44+

tests/cases/compiler/arrayFlatMap.ts

+6
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@ const array: number[] = [];
44
const readonlyArray: ReadonlyArray<number> = [];
55
array.flatMap((): ReadonlyArray<number> => []); // ok
66
readonlyArray.flatMap((): ReadonlyArray<number> => []); // ok
7+
8+
// #19535
9+
10+
declare function f(): number[] | number[][];
11+
const [x] = [1].flatMap(f);
12+
x == 1;

0 commit comments

Comments
 (0)