Skip to content

Commit 0056e90

Browse files
committed
Add tests
1 parent 02e3753 commit 0056e90

12 files changed

+204
-1
lines changed

Diff for: tests/baselines/reference/arrayConcat2.js

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

77
var b = new Array<string>();
88
b.concat('hello');
9+
10+
const expected: undefined = undefined as Flatten<undefined>;
11+
12+
// #19535
13+
14+
const [x] = (undefined as unknown as string[][]).concat([""]);
15+
x == "";
16+
17+
// #26378
18+
19+
[""].concat([1]);
20+
21+
// #26976
22+
23+
[].concat([""]);
924

1025

1126
//// [arrayConcat2.js]
@@ -14,3 +29,11 @@ a.concat("hello", 'world');
1429
a.concat('Hello');
1530
var b = new Array();
1631
b.concat('hello');
32+
var expected = undefined;
33+
// #19535
34+
var x = undefined.concat([""])[0];
35+
x == "";
36+
// #26378
37+
[""].concat([1]);
38+
// #26976
39+
[].concat([""]);

Diff for: tests/baselines/reference/arrayConcat2.symbols

+28
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,31 @@ 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+
const expected: undefined = undefined as Flatten<undefined>;
25+
>expected : Symbol(expected, Decl(arrayConcat2.ts, 8, 5))
26+
>undefined : Symbol(undefined)
27+
>Flatten : Symbol(Flatten, Decl(lib.es5.d.ts, --, --))
28+
29+
// #19535
30+
31+
const [x] = (undefined as unknown as string[][]).concat([""]);
32+
>x : Symbol(x, Decl(arrayConcat2.ts, 12, 7))
33+
>(undefined as unknown as string[][]).concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
34+
>undefined : Symbol(undefined)
35+
>concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
36+
37+
x == "";
38+
>x : Symbol(x, Decl(arrayConcat2.ts, 12, 7))
39+
40+
// #26378
41+
42+
[""].concat([1]);
43+
>[""].concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
44+
>concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
45+
46+
// #26976
47+
48+
[].concat([""]);
49+
>[].concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
50+
>concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
51+

Diff for: tests/baselines/reference/arrayConcat2.types

+46-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,48 @@ b.concat('hello');
3030
>concat : { (...items: ConcatArray<string>[]): string[]; <U extends any[]>(...items: U): (string | Flatten<U[number]>)[]; }
3131
>'hello' : "hello"
3232

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

Diff for: tests/baselines/reference/arrayFlat.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//// [arrayFlat.ts]
2+
// #24579 and #29604
3+
4+
const [x] = [[""], [1]].flat();
5+
const assert: any extends typeof x ? true : false = false;
6+
7+
8+
//// [arrayFlat.js]
9+
// #24579 and #29604
10+
var x = [[""], [1]].flat()[0];
11+
var assert = false;

Diff for: tests/baselines/reference/arrayFlat.symbols

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
=== tests/cases/compiler/arrayFlat.ts ===
2+
// #24579 and #29604
3+
4+
const [x] = [[""], [1]].flat();
5+
>x : Symbol(x, Decl(arrayFlat.ts, 2, 7))
6+
>[[""], [1]].flat : Symbol(Array.flat, Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --) ... and 1 more)
7+
>flat : Symbol(Array.flat, Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --) ... and 1 more)
8+
9+
const assert: any extends typeof x ? true : false = false;
10+
>assert : Symbol(assert, Decl(arrayFlat.ts, 3, 5))
11+
>x : Symbol(x, Decl(arrayFlat.ts, 2, 7))
12+

Diff for: tests/baselines/reference/arrayFlat.types

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
=== tests/cases/compiler/arrayFlat.ts ===
2+
// #24579 and #29604
3+
4+
const [x] = [[""], [1]].flat();
5+
>x : string | number
6+
>[[""], [1]].flat() : (string | number)[]
7+
>[[""], [1]].flat : { (depth: 4): (string | number)[]; (depth: 3): (string | number)[]; (depth: 2): (string | number)[]; (depth?: 1): (string | number)[]; (depth: 0): (string[] | number[])[]; (depth: number): (string | number | string[] | number[])[]; }
8+
>[[""], [1]] : (string[] | number[])[]
9+
>[""] : string[]
10+
>"" : ""
11+
>[1] : number[]
12+
>1 : 1
13+
>flat : { (depth: 4): (string | number)[]; (depth: 3): (string | number)[]; (depth: 2): (string | number)[]; (depth?: 1): (string | number)[]; (depth: 0): (string[] | number[])[]; (depth: number): (string | number | string[] | number[])[]; }
14+
15+
const assert: any extends typeof x ? true : false = false;
16+
>assert : boolean
17+
>x : string | number
18+
>true : true
19+
>false : false
20+
>false : false
21+

Diff for: 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+
const [x] = [""].flatMap(undefined as () => string[] | string[][]);
10+
x == "";
611

712

813
//// [arrayFlatMap.js]
914
var array = [];
1015
var readonlyArray = [];
1116
array.flatMap(function () { return []; }); // ok
1217
readonlyArray.flatMap(function () { return []; }); // ok
18+
// #19535
19+
var x = [""].flatMap(undefined)[0];
20+
x == "";

Diff for: tests/baselines/reference/arrayFlatMap.symbols

+11
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,14 @@ 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+
const [x] = [""].flatMap(undefined as () => string[] | string[][]);
24+
>x : Symbol(x, Decl(arrayFlatMap.ts, 7, 7))
25+
>[""].flatMap : Symbol(Array.flatMap, Decl(lib.es2019.array.d.ts, --, --))
26+
>flatMap : Symbol(Array.flatMap, Decl(lib.es2019.array.d.ts, --, --))
27+
>undefined : Symbol(undefined)
28+
29+
x == "";
30+
>x : Symbol(x, Decl(arrayFlatMap.ts, 7, 7))
31+

Diff for: tests/baselines/reference/arrayFlatMap.types

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

26+
// #19535
27+
28+
const [x] = [""].flatMap(undefined as () => string[] | string[][]);
29+
>x : string | string[]
30+
>[""].flatMap(undefined as () => string[] | string[][]) : (string | string[])[]
31+
>[""].flatMap : <U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => Flatten<U>[]
32+
>[""] : string[]
33+
>"" : ""
34+
>flatMap : <U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => Flatten<U>[]
35+
>undefined as () => string[] | string[][] : () => string[] | string[][]
36+
>undefined : undefined
37+
38+
x == "";
39+
>x == "" : boolean
40+
>x : string | string[]
41+
>"" : ""
42+

Diff for: tests/cases/compiler/arrayConcat2.ts

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

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

Diff for: tests/cases/compiler/arrayFlat.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// @lib: es2019
2+
3+
// #24579 and #29604
4+
5+
const [x] = [[""], [1]].flat();
6+
const assert: any extends typeof x ? true : false = false;

Diff for: tests/cases/compiler/arrayFlatMap.ts

+5
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@ 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+
const [x] = [""].flatMap(undefined as () => string[] | string[][]);
11+
x == "";

0 commit comments

Comments
 (0)