Skip to content

Commit 7cf1280

Browse files
committed
Add tests
1 parent 8c1e5e1 commit 7cf1280

File tree

8 files changed

+152
-1
lines changed

8 files changed

+152
-1
lines changed

tests/baselines/reference/arrayConcat2.js

+22
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@ a.concat('Hello');
66

77
var b = new Array<string>();
88
b.concat('hello');
9+
10+
// #19535
11+
12+
const c: number[][] = [];
13+
const [x] = c.concat([1]);
14+
x == 1;
15+
16+
// #26378
17+
18+
[1].concat(['a']);
19+
20+
// #26976
21+
22+
[].concat([1]);
923

1024

1125
//// [arrayConcat2.js]
@@ -14,3 +28,11 @@ a.concat("hello", 'world');
1428
a.concat('Hello');
1529
var b = new Array();
1630
b.concat('hello');
31+
// #19535
32+
var c = [];
33+
var x = c.concat([1])[0];
34+
x == 1;
35+
// #26378
36+
[1].concat(['a']);
37+
// #26976
38+
[].concat([1]);

tests/baselines/reference/arrayConcat2.symbols

+26
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,29 @@ b.concat('hello');
2121
>b : Symbol(b, Decl(arrayConcat2.ts, 5, 3))
2222
>concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
2323

24+
// #19535
25+
26+
const c: number[][] = [];
27+
>c : Symbol(c, Decl(arrayConcat2.ts, 10, 5))
28+
29+
const [x] = c.concat([1]);
30+
>x : Symbol(x, Decl(arrayConcat2.ts, 11, 7))
31+
>c.concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
32+
>c : Symbol(c, Decl(arrayConcat2.ts, 10, 5))
33+
>concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
34+
35+
x == 1;
36+
>x : Symbol(x, Decl(arrayConcat2.ts, 11, 7))
37+
38+
// #26378
39+
40+
[1].concat(['a']);
41+
>[1].concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
42+
>concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
43+
44+
// #26976
45+
46+
[].concat([1]);
47+
>[].concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
48+
>concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
49+

tests/baselines/reference/arrayConcat2.types

+42-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
=== tests/cases/compiler/arrayConcat2.ts ===
22
var a: string[] = [];
33
>a : string[]
4-
>[] : undefined[]
4+
>[] : never[]
55

66
a.concat("hello", 'world');
77
>a.concat("hello", 'world') : string[]
@@ -30,3 +30,44 @@ b.concat('hello');
3030
>concat : { (...items: ConcatArray<string>[]): string[]; <U extends any[]>(...items: U): (string | ConcatFlatten<U[number]>)[]; }
3131
>'hello' : "hello"
3232

33+
// #19535
34+
35+
const c: number[][] = [];
36+
>c : number[][]
37+
>[] : never[]
38+
39+
const [x] = c.concat([1]);
40+
>x : number | number[]
41+
>c.concat([1]) : (number | number[])[]
42+
>c.concat : { (...items: ConcatArray<number[]>[]): number[][]; <U extends any[]>(...items: U): (number[] | ConcatFlatten<U[number]>)[]; }
43+
>c : number[][]
44+
>concat : { (...items: ConcatArray<number[]>[]): number[][]; <U extends any[]>(...items: U): (number[] | ConcatFlatten<U[number]>)[]; }
45+
>[1] : number[]
46+
>1 : 1
47+
48+
x == 1;
49+
>x == 1 : boolean
50+
>x : number | number[]
51+
>1 : 1
52+
53+
// #26378
54+
55+
[1].concat(['a']);
56+
>[1].concat(['a']) : (string | number)[]
57+
>[1].concat : { (...items: ConcatArray<number>[]): number[]; <U extends any[]>(...items: U): (number | ConcatFlatten<U[number]>)[]; }
58+
>[1] : number[]
59+
>1 : 1
60+
>concat : { (...items: ConcatArray<number>[]): number[]; <U extends any[]>(...items: U): (number | ConcatFlatten<U[number]>)[]; }
61+
>['a'] : string[]
62+
>'a' : "a"
63+
64+
// #26976
65+
66+
[].concat([1]);
67+
>[].concat([1]) : number[]
68+
>[].concat : { (...items: ConcatArray<never>[]): never[]; <U extends any[]>(...items: U): ConcatFlatten<U[number]>[]; }
69+
>[] : never[]
70+
>concat : { (...items: ConcatArray<never>[]): never[]; <U extends any[]>(...items: U): ConcatFlatten<U[number]>[]; }
71+
>[1] : number[]
72+
>1 : 1
73+

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>(callback: (this: This, value: number, index: number, array: number[]) => U, thisArg?: This) => (U extends readonly (infer V)[] ? V : U)[]
35+
>[1] : number[]
36+
>1 : 1
37+
>flatMap : <U, This = undefined>(callback: (this: This, value: number, index: number, array: number[]) => 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/arrayConcat2.ts

+15
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,18 @@ a.concat('Hello');
55

66
var b = new Array<string>();
77
b.concat('hello');
8+
9+
// #19535
10+
11+
const c: number[][] = [];
12+
const [x] = c.concat([1]);
13+
x == 1;
14+
15+
// #26378
16+
17+
[1].concat(['a']);
18+
19+
// #26976
20+
21+
// @strictNullChecks: true
22+
[].concat([1]);

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)