Skip to content

Commit 43679d2

Browse files
committed
Add tests
1 parent bdc9366 commit 43679d2

12 files changed

+282
-1
lines changed

tests/baselines/reference/arrayConcat2.js

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

77
var b = new Array<string>();
88
b.concat('hello');
9+
10+
const expected1: undefined = undefined as Flatten<undefined>;
11+
12+
// #19535
13+
14+
let [actual2] = (undefined as unknown as string[][]).concat([""]);
15+
const expected2: string | string[] = actual2;
16+
actual2 = undefined as unknown as string | string[];
17+
18+
// #26378
19+
20+
let [actual3] = [""].concat([1]);
21+
const expected3: string | number = actual3;
22+
actual3 = undefined as unknown as string | number;
23+
24+
// #26976
25+
26+
[].concat([""]);
927

1028

1129
//// [arrayConcat2.js]
@@ -14,3 +32,14 @@ a.concat("hello", 'world');
1432
a.concat('Hello');
1533
var b = new Array();
1634
b.concat('hello');
35+
var expected1 = undefined;
36+
// #19535
37+
var actual2 = undefined.concat([""])[0];
38+
var expected2 = actual2;
39+
actual2 = undefined;
40+
// #26378
41+
var actual3 = [""].concat([1])[0];
42+
var expected3 = actual3;
43+
actual3 = undefined;
44+
// #26976
45+
[].concat([""]);

tests/baselines/reference/arrayConcat2.symbols

+42
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,45 @@ 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 expected1: undefined = undefined as Flatten<undefined>;
25+
>expected1 : Symbol(expected1, Decl(arrayConcat2.ts, 8, 5))
26+
>undefined : Symbol(undefined)
27+
>Flatten : Symbol(Flatten, Decl(lib.es5.d.ts, --, --))
28+
29+
// #19535
30+
31+
let [actual2] = (undefined as unknown as string[][]).concat([""]);
32+
>actual2 : Symbol(actual2, Decl(arrayConcat2.ts, 12, 5))
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+
const expected2: string | string[] = actual2;
38+
>expected2 : Symbol(expected2, Decl(arrayConcat2.ts, 13, 5))
39+
>actual2 : Symbol(actual2, Decl(arrayConcat2.ts, 12, 5))
40+
41+
actual2 = undefined as unknown as string | string[];
42+
>actual2 : Symbol(actual2, Decl(arrayConcat2.ts, 12, 5))
43+
>undefined : Symbol(undefined)
44+
45+
// #26378
46+
47+
let [actual3] = [""].concat([1]);
48+
>actual3 : Symbol(actual3, Decl(arrayConcat2.ts, 18, 5))
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+
52+
const expected3: string | number = actual3;
53+
>expected3 : Symbol(expected3, Decl(arrayConcat2.ts, 19, 5))
54+
>actual3 : Symbol(actual3, Decl(arrayConcat2.ts, 18, 5))
55+
56+
actual3 = undefined as unknown as string | number;
57+
>actual3 : Symbol(actual3, Decl(arrayConcat2.ts, 18, 5))
58+
>undefined : Symbol(undefined)
59+
60+
// #26976
61+
62+
[].concat([""]);
63+
>[].concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
64+
>concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
65+

tests/baselines/reference/arrayConcat2.types

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

33+
const expected1: undefined = undefined as Flatten<undefined>;
34+
>expected1 : undefined
35+
>undefined as Flatten<undefined> : undefined
36+
>undefined : undefined
37+
38+
// #19535
39+
40+
let [actual2] = (undefined as unknown as string[][]).concat([""]);
41+
>actual2 : 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+
const expected2: string | string[] = actual2;
53+
>expected2 : string | string[]
54+
>actual2 : string | string[]
55+
56+
actual2 = undefined as unknown as string | string[];
57+
>actual2 = undefined as unknown as string | string[] : string | string[]
58+
>actual2 : string | string[]
59+
>undefined as unknown as string | string[] : string | string[]
60+
>undefined as unknown : unknown
61+
>undefined : undefined
62+
63+
// #26378
64+
65+
let [actual3] = [""].concat([1]);
66+
>actual3 : string | number
67+
>[""].concat([1]) : (string | number)[]
68+
>[""].concat : { (...items: ConcatArray<string>[]): string[]; <U extends any[]>(...items: U): (string | Flatten<U[number]>)[]; }
69+
>[""] : string[]
70+
>"" : ""
71+
>concat : { (...items: ConcatArray<string>[]): string[]; <U extends any[]>(...items: U): (string | Flatten<U[number]>)[]; }
72+
>[1] : number[]
73+
>1 : 1
74+
75+
const expected3: string | number = actual3;
76+
>expected3 : string | number
77+
>actual3 : string | number
78+
79+
actual3 = undefined as unknown as string | number;
80+
>actual3 = undefined as unknown as string | number : string | number
81+
>actual3 : string | number
82+
>undefined as unknown as string | number : string | number
83+
>undefined as unknown : unknown
84+
>undefined : undefined
85+
86+
// #26976
87+
88+
[].concat([""]);
89+
>[].concat([""]) : string[]
90+
>[].concat : { (...items: ConcatArray<never>[]): never[]; <U extends any[]>(...items: U): Flatten<U[number]>[]; }
91+
>[] : never[]
92+
>concat : { (...items: ConcatArray<never>[]): never[]; <U extends any[]>(...items: U): Flatten<U[number]>[]; }
93+
>[""] : string[]
94+
>"" : ""
95+
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//// [arrayFlat.ts]
2+
// #24579 and #29604
3+
4+
let [actual] = [[""], [1]].flat();
5+
const expected: string | number = actual;
6+
actual = undefined as string | number;
7+
const f: any extends typeof actual ? true : false = false;
8+
9+
10+
//// [arrayFlat.js]
11+
// #24579 and #29604
12+
var actual = [[""], [1]].flat()[0];
13+
var expected = actual;
14+
actual = undefined;
15+
var f = false;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
=== tests/cases/compiler/arrayFlat.ts ===
2+
// #24579 and #29604
3+
4+
let [actual] = [[""], [1]].flat();
5+
>actual : Symbol(actual, Decl(arrayFlat.ts, 2, 5))
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 expected: string | number = actual;
10+
>expected : Symbol(expected, Decl(arrayFlat.ts, 3, 5))
11+
>actual : Symbol(actual, Decl(arrayFlat.ts, 2, 5))
12+
13+
actual = undefined as string | number;
14+
>actual : Symbol(actual, Decl(arrayFlat.ts, 2, 5))
15+
>undefined : Symbol(undefined)
16+
17+
const f: any extends typeof actual ? true : false = false;
18+
>f : Symbol(f, Decl(arrayFlat.ts, 5, 5))
19+
>actual : Symbol(actual, Decl(arrayFlat.ts, 2, 5))
20+
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
=== tests/cases/compiler/arrayFlat.ts ===
2+
// #24579 and #29604
3+
4+
let [actual] = [[""], [1]].flat();
5+
>actual : 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 expected: string | number = actual;
16+
>expected : string | number
17+
>actual : string | number
18+
19+
actual = undefined as string | number;
20+
>actual = undefined as string | number : string | number
21+
>actual : string | number
22+
>undefined as string | number : string | number
23+
>undefined : undefined
24+
25+
const f: any extends typeof actual ? true : false = false;
26+
>f : boolean
27+
>actual : string | number
28+
>true : true
29+
>false : false
30+
>false : false
31+

tests/baselines/reference/arrayFlatMap.js

+10
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,20 @@ 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+
let [actual] = [""].flatMap(undefined as () => string[] | string[][]);
10+
const expected: string | string[] = actual;
11+
actual = undefined as string | string[];
612

713

814
//// [arrayFlatMap.js]
915
var array = [];
1016
var readonlyArray = [];
1117
array.flatMap(function () { return []; }); // ok
1218
readonlyArray.flatMap(function () { return []; }); // ok
19+
// #19535
20+
var actual = [""].flatMap(undefined)[0];
21+
var expected = actual;
22+
actual = undefined;

tests/baselines/reference/arrayFlatMap.symbols

+16
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,19 @@ 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+
let [actual] = [""].flatMap(undefined as () => string[] | string[][]);
24+
>actual : Symbol(actual, Decl(arrayFlatMap.ts, 7, 5))
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+
const expected: string | string[] = actual;
30+
>expected : Symbol(expected, Decl(arrayFlatMap.ts, 8, 5))
31+
>actual : Symbol(actual, Decl(arrayFlatMap.ts, 7, 5))
32+
33+
actual = undefined as string | string[];
34+
>actual : Symbol(actual, Decl(arrayFlatMap.ts, 7, 5))
35+
>undefined : Symbol(undefined)
36+

tests/baselines/reference/arrayFlatMap.types

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

26+
// #19535
27+
28+
let [actual] = [""].flatMap(undefined as () => string[] | string[][]);
29+
>actual : 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+
const expected: string | string[] = actual;
39+
>expected : string | string[]
40+
>actual : string | string[]
41+
42+
actual = undefined as string | string[];
43+
>actual = undefined as string | string[] : string | string[]
44+
>actual : string | string[]
45+
>undefined as string | string[] : string | string[]
46+
>undefined : undefined
47+

tests/cases/compiler/arrayConcat2.ts

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

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

tests/cases/compiler/arrayFlat.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @lib: es2019
2+
3+
// #24579 and #29604
4+
5+
let [actual] = [[""], [1]].flat();
6+
const expected: string | number = actual;
7+
actual = undefined as string | number;
8+
const f: any extends typeof actual ? true : false = false;

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+
let [actual] = [""].flatMap(undefined as () => string[] | string[][]);
11+
const expected: string | string[] = actual;
12+
actual = undefined as string | string[];

0 commit comments

Comments
 (0)