Skip to content

Commit f242e25

Browse files
committed
Update baselines for reduce/reduceRight overload reordering
The overload order change affects the displayed type signature and improves type inference in some cases (e.g., anyInferenceAnonymousFunctions now correctly infers any[] instead of any when reduce is called with [] as the initial value).
1 parent 9f60978 commit f242e25

27 files changed

+215
-197
lines changed

tests/baselines/reference/anyInferenceAnonymousFunctions.symbols

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ paired.reduce(function (a1, a2) {
1212
>a2 : Symbol(a2, Decl(anyInferenceAnonymousFunctions.ts, 2, 27))
1313

1414
return a1.concat({});
15+
>a1.concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
1516
>a1 : Symbol(a1, Decl(anyInferenceAnonymousFunctions.ts, 2, 24))
17+
>concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
1618

1719
} , []);
1820

@@ -24,7 +26,9 @@ paired.reduce((b1, b2) => {
2426
>b2 : Symbol(b2, Decl(anyInferenceAnonymousFunctions.ts, 8, 18))
2527

2628
return b1.concat({});
29+
>b1.concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
2730
>b1 : Symbol(b1, Decl(anyInferenceAnonymousFunctions.ts, 8, 15))
31+
>concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
2832

2933
} , []);
3034

@@ -34,7 +38,9 @@ paired.reduce((b3, b4) => b3.concat({}), []);
3438
>reduce : Symbol(Array.reduce, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
3539
>b3 : Symbol(b3, Decl(anyInferenceAnonymousFunctions.ts, 13, 15))
3640
>b4 : Symbol(b4, Decl(anyInferenceAnonymousFunctions.ts, 13, 18))
41+
>b3.concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
3742
>b3 : Symbol(b3, Decl(anyInferenceAnonymousFunctions.ts, 13, 15))
43+
>concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
3844

3945
paired.map((c1) => c1.count);
4046
>paired.map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --))

tests/baselines/reference/anyInferenceAnonymousFunctions.types

Lines changed: 54 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,29 @@ var paired: any[];
66
> : ^^^^^
77

88
paired.reduce(function (a1, a2) {
9-
>paired.reduce(function (a1, a2) { return a1.concat({});} , []) : any
10-
>paired.reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any): any; (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue: any): any; <U>(callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; }
11-
> : ^^^ ^^^ ^^^^^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^ ^^^ ^^^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^
9+
>paired.reduce(function (a1, a2) { return a1.concat({});} , []) : any[]
10+
> : ^^^^^
11+
>paired.reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any): any; <U>(callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue: any): any; }
12+
> : ^^^ ^^^ ^^^^^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^ ^^^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^ ^^^^^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^
1213
>paired : any[]
1314
> : ^^^^^
14-
>reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any): any; (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue: any): any; <U>(callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; }
15-
> : ^^^ ^^^ ^^^^^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^ ^^^ ^^^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^
16-
>function (a1, a2) { return a1.concat({});} : (a1: any, a2: any) => any
17-
> : ^ ^^^^^^^ ^^^^^^^^^^^^^
18-
>a1 : any
15+
>reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any): any; <U>(callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue: any): any; }
16+
> : ^^^ ^^^ ^^^^^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^ ^^^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^ ^^^^^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^
17+
>function (a1, a2) { return a1.concat({});} : (a1: any[], a2: any) => any[]
18+
> : ^ ^^^^^^^^^ ^^^^^^^^^^^^^^^
19+
>a1 : any[]
20+
> : ^^^^^
1921
>a2 : any
2022

2123
return a1.concat({});
22-
>a1.concat({}) : any
23-
>a1.concat : any
24-
>a1 : any
25-
> : ^^^
26-
>concat : any
27-
> : ^^^
24+
>a1.concat({}) : any[]
25+
> : ^^^^^
26+
>a1.concat : { (...items: ConcatArray<any>[]): any[]; (...items: any[]): any[]; }
27+
> : ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^
28+
>a1 : any[]
29+
> : ^^^^^
30+
>concat : { (...items: ConcatArray<any>[]): any[]; (...items: any[]): any[]; }
31+
> : ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^
2832
>{} : {}
2933
> : ^^
3034

@@ -33,25 +37,29 @@ paired.reduce(function (a1, a2) {
3337
> : ^^^^^^^^^^^
3438

3539
paired.reduce((b1, b2) => {
36-
>paired.reduce((b1, b2) => { return b1.concat({});} , []) : any
37-
>paired.reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any): any; (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue: any): any; <U>(callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; }
38-
> : ^^^ ^^^ ^^^^^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^ ^^^ ^^^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^
40+
>paired.reduce((b1, b2) => { return b1.concat({});} , []) : any[]
41+
> : ^^^^^
42+
>paired.reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any): any; <U>(callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue: any): any; }
43+
> : ^^^ ^^^ ^^^^^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^ ^^^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^ ^^^^^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^
3944
>paired : any[]
4045
> : ^^^^^
41-
>reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any): any; (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue: any): any; <U>(callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; }
42-
> : ^^^ ^^^ ^^^^^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^ ^^^ ^^^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^
43-
>(b1, b2) => { return b1.concat({});} : (b1: any, b2: any) => any
44-
> : ^ ^^^^^^^ ^^^^^^^^^^^^^
45-
>b1 : any
46+
>reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any): any; <U>(callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue: any): any; }
47+
> : ^^^ ^^^ ^^^^^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^ ^^^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^ ^^^^^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^
48+
>(b1, b2) => { return b1.concat({});} : (b1: any[], b2: any) => any[]
49+
> : ^ ^^^^^^^^^ ^^^^^^^^^^^^^^^
50+
>b1 : any[]
51+
> : ^^^^^
4652
>b2 : any
4753

4854
return b1.concat({});
49-
>b1.concat({}) : any
50-
>b1.concat : any
51-
>b1 : any
52-
> : ^^^
53-
>concat : any
54-
> : ^^^
55+
>b1.concat({}) : any[]
56+
> : ^^^^^
57+
>b1.concat : { (...items: ConcatArray<any>[]): any[]; (...items: any[]): any[]; }
58+
> : ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^
59+
>b1 : any[]
60+
> : ^^^^^
61+
>concat : { (...items: ConcatArray<any>[]): any[]; (...items: any[]): any[]; }
62+
> : ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^
5563
>{} : {}
5664
> : ^^
5765

@@ -60,23 +68,27 @@ paired.reduce((b1, b2) => {
6068
> : ^^^^^^^^^^^
6169

6270
paired.reduce((b3, b4) => b3.concat({}), []);
63-
>paired.reduce((b3, b4) => b3.concat({}), []) : any
64-
>paired.reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any): any; (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue: any): any; <U>(callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; }
65-
> : ^^^ ^^^ ^^^^^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^ ^^^ ^^^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^
71+
>paired.reduce((b3, b4) => b3.concat({}), []) : any[]
72+
> : ^^^^^
73+
>paired.reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any): any; <U>(callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue: any): any; }
74+
> : ^^^ ^^^ ^^^^^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^ ^^^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^ ^^^^^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^
6675
>paired : any[]
6776
> : ^^^^^
68-
>reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any): any; (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue: any): any; <U>(callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; }
69-
> : ^^^ ^^^ ^^^^^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^ ^^^ ^^^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^
70-
>(b3, b4) => b3.concat({}) : (b3: any, b4: any) => any
71-
> : ^ ^^^^^^^ ^^^^^^^^^^^^^
72-
>b3 : any
77+
>reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any): any; <U>(callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue: any): any; }
78+
> : ^^^ ^^^ ^^^^^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^ ^^^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^ ^^^^^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^
79+
>(b3, b4) => b3.concat({}) : (b3: any[], b4: any) => any[]
80+
> : ^ ^^^^^^^^^ ^^^^^^^^^^^^^^^
81+
>b3 : any[]
82+
> : ^^^^^
7383
>b4 : any
74-
>b3.concat({}) : any
75-
>b3.concat : any
76-
>b3 : any
77-
> : ^^^
78-
>concat : any
79-
> : ^^^
84+
>b3.concat({}) : any[]
85+
> : ^^^^^
86+
>b3.concat : { (...items: ConcatArray<any>[]): any[]; (...items: any[]): any[]; }
87+
> : ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^
88+
>b3 : any[]
89+
> : ^^^^^
90+
>concat : { (...items: ConcatArray<any>[]): any[]; (...items: any[]): any[]; }
91+
> : ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^
8092
>{} : {}
8193
> : ^^
8294
>[] : undefined[]

tests/baselines/reference/destructuringTuple.errors.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
destructuringTuple.ts(11,7): error TS2461: Type 'number' is not an array type.
1+
destructuringTuple.ts(11,8): error TS2493: Tuple type '[]' of length '0' has no element at index '0'.
22
destructuringTuple.ts(11,48): error TS2769: No overload matches this call.
3-
Overload 1 of 3, '(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number', gave the following error.
4-
Type 'never[]' is not assignable to type 'number'.
5-
Overload 2 of 3, '(callbackfn: (previousValue: [], currentValue: number, currentIndex: number, array: number[]) => [], initialValue: []): []', gave the following error.
3+
Overload 1 of 3, '(callbackfn: (previousValue: [], currentValue: number, currentIndex: number, array: number[]) => [], initialValue: []): []', gave the following error.
64
Type 'never[]' is not assignable to type '[]'.
75
Target allows only 0 element(s) but source may have more.
6+
Overload 2 of 3, '(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number', gave the following error.
7+
Type 'never[]' is not assignable to type 'number'.
88
destructuringTuple.ts(11,60): error TS2769: No overload matches this call.
99
Overload 1 of 2, '(...items: ConcatArray<never>[]): never[]', gave the following error.
1010
Argument of type 'number' is not assignable to parameter of type 'ConcatArray<never>'.
@@ -24,15 +24,15 @@ destructuringTuple.ts(11,60): error TS2769: No overload matches this call.
2424
// Repros from #32140
2525

2626
const [oops1] = [1, 2, 3].reduce((accu, el) => accu.concat(el), []);
27-
~~~~~~~
28-
!!! error TS2461: Type 'number' is not an array type.
27+
~~~~~
28+
!!! error TS2493: Tuple type '[]' of length '0' has no element at index '0'.
2929
~~~~~~~~~~~~~~~
3030
!!! error TS2769: No overload matches this call.
31-
!!! error TS2769: Overload 1 of 3, '(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number', gave the following error.
32-
!!! error TS2769: Type 'never[]' is not assignable to type 'number'.
33-
!!! error TS2769: Overload 2 of 3, '(callbackfn: (previousValue: [], currentValue: number, currentIndex: number, array: number[]) => [], initialValue: []): []', gave the following error.
31+
!!! error TS2769: Overload 1 of 3, '(callbackfn: (previousValue: [], currentValue: number, currentIndex: number, array: number[]) => [], initialValue: []): []', gave the following error.
3432
!!! error TS2769: Type 'never[]' is not assignable to type '[]'.
3533
!!! error TS2769: Target allows only 0 element(s) but source may have more.
34+
!!! error TS2769: Overload 2 of 3, '(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number', gave the following error.
35+
!!! error TS2769: Type 'never[]' is not assignable to type 'number'.
3636
!!! related TS6502 lib.es5.d.ts:--:--: The expected type comes from the return type of this signature.
3737
!!! related TS6502 lib.es5.d.ts:--:--: The expected type comes from the return type of this signature.
3838
~~

0 commit comments

Comments
 (0)