Skip to content

Commit d4973d5

Browse files
author
Andy Hanson
committed
Remove redundant 'reduce' overloads
1 parent 9320699 commit d4973d5

7 files changed

Lines changed: 95 additions & 35 deletions

File tree

src/lib/es5.d.ts

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ interface TemplateStringsArray extends ReadonlyArray<string> {
577577

578578
/**
579579
* The type of `import.meta`.
580-
*
580+
*
581581
* If you need to declare that a given property exists on `import.meta`,
582582
* this type may be augmented via interface merging.
583583
*/
@@ -1141,7 +1141,6 @@ interface ReadonlyArray<T> {
11411141
* @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
11421142
*/
11431143
reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: ReadonlyArray<T>) => T): T;
1144-
reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: ReadonlyArray<T>) => T, initialValue: T): T;
11451144
/**
11461145
* Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
11471146
* @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.
@@ -1154,7 +1153,6 @@ interface ReadonlyArray<T> {
11541153
* @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
11551154
*/
11561155
reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: ReadonlyArray<T>) => T): T;
1157-
reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: ReadonlyArray<T>) => T, initialValue: T): T;
11581156
/**
11591157
* Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
11601158
* @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.
@@ -1300,7 +1298,6 @@ interface Array<T> {
13001298
* @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
13011299
*/
13021300
reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T;
1303-
reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T;
13041301
/**
13051302
* Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
13061303
* @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.
@@ -1313,7 +1310,6 @@ interface Array<T> {
13131310
* @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
13141311
*/
13151312
reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T;
1316-
reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T;
13171313
/**
13181314
* Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
13191315
* @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.
@@ -1791,7 +1787,6 @@ interface Int8Array {
17911787
* instead of an array value.
17921788
*/
17931789
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int8Array) => number): number;
1794-
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int8Array) => number, initialValue: number): number;
17951790

17961791
/**
17971792
* Calls the specified callback function for all the elements in an array. The return value of
@@ -1816,7 +1811,6 @@ interface Int8Array {
18161811
* argument instead of an array value.
18171812
*/
18181813
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int8Array) => number): number;
1819-
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int8Array) => number, initialValue: number): number;
18201814

18211815
/**
18221816
* Calls the specified callback function for all the elements in an array, in descending order.
@@ -2060,7 +2054,6 @@ interface Uint8Array {
20602054
* instead of an array value.
20612055
*/
20622056
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint8Array) => number): number;
2063-
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint8Array) => number, initialValue: number): number;
20642057

20652058
/**
20662059
* Calls the specified callback function for all the elements in an array. The return value of
@@ -2085,7 +2078,6 @@ interface Uint8Array {
20852078
* argument instead of an array value.
20862079
*/
20872080
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint8Array) => number): number;
2088-
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint8Array) => number, initialValue: number): number;
20892081

20902082
/**
20912083
* Calls the specified callback function for all the elements in an array, in descending order.
@@ -2329,7 +2321,6 @@ interface Uint8ClampedArray {
23292321
* instead of an array value.
23302322
*/
23312323
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint8ClampedArray) => number): number;
2332-
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint8ClampedArray) => number, initialValue: number): number;
23332324

23342325
/**
23352326
* Calls the specified callback function for all the elements in an array. The return value of
@@ -2354,7 +2345,6 @@ interface Uint8ClampedArray {
23542345
* argument instead of an array value.
23552346
*/
23562347
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint8ClampedArray) => number): number;
2357-
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint8ClampedArray) => number, initialValue: number): number;
23582348

23592349
/**
23602350
* Calls the specified callback function for all the elements in an array, in descending order.
@@ -2596,7 +2586,6 @@ interface Int16Array {
25962586
* instead of an array value.
25972587
*/
25982588
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int16Array) => number): number;
2599-
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int16Array) => number, initialValue: number): number;
26002589

26012590
/**
26022591
* Calls the specified callback function for all the elements in an array. The return value of
@@ -2621,7 +2610,6 @@ interface Int16Array {
26212610
* argument instead of an array value.
26222611
*/
26232612
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int16Array) => number): number;
2624-
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int16Array) => number, initialValue: number): number;
26252613

26262614
/**
26272615
* Calls the specified callback function for all the elements in an array, in descending order.
@@ -2866,7 +2854,6 @@ interface Uint16Array {
28662854
* instead of an array value.
28672855
*/
28682856
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint16Array) => number): number;
2869-
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint16Array) => number, initialValue: number): number;
28702857

28712858
/**
28722859
* Calls the specified callback function for all the elements in an array. The return value of
@@ -2891,7 +2878,6 @@ interface Uint16Array {
28912878
* argument instead of an array value.
28922879
*/
28932880
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint16Array) => number): number;
2894-
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint16Array) => number, initialValue: number): number;
28952881

28962882
/**
28972883
* Calls the specified callback function for all the elements in an array, in descending order.
@@ -3135,7 +3121,6 @@ interface Int32Array {
31353121
* instead of an array value.
31363122
*/
31373123
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int32Array) => number): number;
3138-
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int32Array) => number, initialValue: number): number;
31393124

31403125
/**
31413126
* Calls the specified callback function for all the elements in an array. The return value of
@@ -3160,7 +3145,6 @@ interface Int32Array {
31603145
* argument instead of an array value.
31613146
*/
31623147
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int32Array) => number): number;
3163-
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int32Array) => number, initialValue: number): number;
31643148

31653149
/**
31663150
* Calls the specified callback function for all the elements in an array, in descending order.
@@ -3403,7 +3387,6 @@ interface Uint32Array {
34033387
* instead of an array value.
34043388
*/
34053389
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint32Array) => number): number;
3406-
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint32Array) => number, initialValue: number): number;
34073390

34083391
/**
34093392
* Calls the specified callback function for all the elements in an array. The return value of
@@ -3428,7 +3411,6 @@ interface Uint32Array {
34283411
* argument instead of an array value.
34293412
*/
34303413
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint32Array) => number): number;
3431-
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint32Array) => number, initialValue: number): number;
34323414

34333415
/**
34343416
* Calls the specified callback function for all the elements in an array, in descending order.
@@ -3672,7 +3654,6 @@ interface Float32Array {
36723654
* instead of an array value.
36733655
*/
36743656
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Float32Array) => number): number;
3675-
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Float32Array) => number, initialValue: number): number;
36763657

36773658
/**
36783659
* Calls the specified callback function for all the elements in an array. The return value of
@@ -3697,7 +3678,6 @@ interface Float32Array {
36973678
* argument instead of an array value.
36983679
*/
36993680
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Float32Array) => number): number;
3700-
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Float32Array) => number, initialValue: number): number;
37013681

37023682
/**
37033683
* Calls the specified callback function for all the elements in an array, in descending order.
@@ -3942,7 +3922,6 @@ interface Float64Array {
39423922
* instead of an array value.
39433923
*/
39443924
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Float64Array) => number): number;
3945-
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Float64Array) => number, initialValue: number): number;
39463925

39473926
/**
39483927
* Calls the specified callback function for all the elements in an array. The return value of
@@ -3967,7 +3946,6 @@ interface Float64Array {
39673946
* argument instead of an array value.
39683947
*/
39693948
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Float64Array) => number): number;
3970-
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Float64Array) => number, initialValue: number): number;
39713949

39723950
/**
39733951
* Calls the specified callback function for all the elements in an array, in descending order.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//// [arrayReduce.ts]
2+
function toStrings(arr: ReadonlyArray<object>): string[] {
3+
return arr.reduce((acc, obj) => {
4+
acc.push(obj.toString());
5+
return acc;
6+
}, [] as string[]);
7+
}
8+
9+
10+
//// [arrayReduce.js]
11+
function toStrings(arr) {
12+
return arr.reduce(function (acc, obj) {
13+
acc.push(obj.toString());
14+
return acc;
15+
}, []);
16+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
=== tests/cases/compiler/arrayReduce.ts ===
2+
function toStrings(arr: ReadonlyArray<object>): string[] {
3+
>toStrings : Symbol(toStrings, Decl(arrayReduce.ts, 0, 0))
4+
>arr : Symbol(arr, Decl(arrayReduce.ts, 0, 19))
5+
>ReadonlyArray : Symbol(ReadonlyArray, Decl(lib.es5.d.ts, --, --))
6+
7+
return arr.reduce((acc, obj) => {
8+
>arr.reduce : Symbol(ReadonlyArray.reduce, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
9+
>arr : Symbol(arr, Decl(arrayReduce.ts, 0, 19))
10+
>reduce : Symbol(ReadonlyArray.reduce, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
11+
>acc : Symbol(acc, Decl(arrayReduce.ts, 1, 20))
12+
>obj : Symbol(obj, Decl(arrayReduce.ts, 1, 24))
13+
14+
acc.push(obj.toString());
15+
>acc.push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --))
16+
>acc : Symbol(acc, Decl(arrayReduce.ts, 1, 20))
17+
>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --))
18+
>obj.toString : Symbol(Object.toString, Decl(lib.es5.d.ts, --, --))
19+
>obj : Symbol(obj, Decl(arrayReduce.ts, 1, 24))
20+
>toString : Symbol(Object.toString, Decl(lib.es5.d.ts, --, --))
21+
22+
return acc;
23+
>acc : Symbol(acc, Decl(arrayReduce.ts, 1, 20))
24+
25+
}, [] as string[]);
26+
}
27+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
=== tests/cases/compiler/arrayReduce.ts ===
2+
function toStrings(arr: ReadonlyArray<object>): string[] {
3+
>toStrings : (arr: ReadonlyArray<object>) => string[]
4+
>arr : ReadonlyArray<object>
5+
>ReadonlyArray : ReadonlyArray<T>
6+
7+
return arr.reduce((acc, obj) => {
8+
>arr.reduce((acc, obj) => { acc.push(obj.toString()); return acc; }, [] as string[]) : string[]
9+
>arr.reduce : { (callbackfn: (previousValue: object, currentValue: object, currentIndex: number, array: ReadonlyArray<object>) => object): object; <U>(callbackfn: (previousValue: U, currentValue: object, currentIndex: number, array: ReadonlyArray<object>) => U, initialValue: U): U; }
10+
>arr : ReadonlyArray<object>
11+
>reduce : { (callbackfn: (previousValue: object, currentValue: object, currentIndex: number, array: ReadonlyArray<object>) => object): object; <U>(callbackfn: (previousValue: U, currentValue: object, currentIndex: number, array: ReadonlyArray<object>) => U, initialValue: U): U; }
12+
>(acc, obj) => { acc.push(obj.toString()); return acc; } : (acc: string[], obj: object) => string[]
13+
>acc : string[]
14+
>obj : object
15+
16+
acc.push(obj.toString());
17+
>acc.push(obj.toString()) : number
18+
>acc.push : (...items: string[]) => number
19+
>acc : string[]
20+
>push : (...items: string[]) => number
21+
>obj.toString() : string
22+
>obj.toString : () => string
23+
>obj : object
24+
>toString : () => string
25+
26+
return acc;
27+
>acc : string[]
28+
29+
}, [] as string[]);
30+
>[] as string[] : string[]
31+
>[] : undefined[]
32+
}
33+

tests/baselines/reference/genericReduce.symbols

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ var b = a.map(s => s.length);
1414

1515
var n1 = b.reduce((x, y) => x + y);
1616
>n1 : Symbol(n1, Decl(genericReduce.ts, 2, 3))
17-
>b.reduce : Symbol(Array.reduce, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
17+
>b.reduce : Symbol(Array.reduce, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
1818
>b : Symbol(b, Decl(genericReduce.ts, 1, 3))
19-
>reduce : Symbol(Array.reduce, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
19+
>reduce : Symbol(Array.reduce, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
2020
>x : Symbol(x, Decl(genericReduce.ts, 2, 19))
2121
>y : Symbol(y, Decl(genericReduce.ts, 2, 21))
2222
>x : Symbol(x, Decl(genericReduce.ts, 2, 19))
2323
>y : Symbol(y, Decl(genericReduce.ts, 2, 21))
2424

2525
var n2 = b.reduceRight((x, y) => x + y);
2626
>n2 : Symbol(n2, Decl(genericReduce.ts, 3, 3))
27-
>b.reduceRight : Symbol(Array.reduceRight, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
27+
>b.reduceRight : Symbol(Array.reduceRight, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
2828
>b : Symbol(b, Decl(genericReduce.ts, 1, 3))
29-
>reduceRight : Symbol(Array.reduceRight, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
29+
>reduceRight : Symbol(Array.reduceRight, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
3030
>x : Symbol(x, Decl(genericReduce.ts, 3, 24))
3131
>y : Symbol(y, Decl(genericReduce.ts, 3, 26))
3232
>x : Symbol(x, Decl(genericReduce.ts, 3, 24))
@@ -50,9 +50,9 @@ n2.toExponential(2); // should not error if 'n2' is correctly number.
5050

5151
var n3 = b.reduce<string>( (x, y) => x + y, ""); // Initial value is of type string
5252
>n3 : Symbol(n3, Decl(genericReduce.ts, 10, 3))
53-
>b.reduce : Symbol(Array.reduce, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
53+
>b.reduce : Symbol(Array.reduce, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
5454
>b : Symbol(b, Decl(genericReduce.ts, 1, 3))
55-
>reduce : Symbol(Array.reduce, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
55+
>reduce : Symbol(Array.reduce, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
5656
>x : Symbol(x, Decl(genericReduce.ts, 10, 28))
5757
>y : Symbol(y, Decl(genericReduce.ts, 10, 30))
5858
>x : Symbol(x, Decl(genericReduce.ts, 10, 28))

0 commit comments

Comments
 (0)