Skip to content

Commit ebc4a6d

Browse files
author
Andy Hanson
committed
Remove redundant 'reduce' overloads
1 parent 1579bfd commit ebc4a6d

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
@@ -517,7 +517,7 @@ interface TemplateStringsArray extends ReadonlyArray<string> {
517517

518518
/**
519519
* The type of `import.meta`.
520-
*
520+
*
521521
* If you need to declare that a given property exists on `import.meta`,
522522
* this type may be augmented via interface merging.
523523
*/
@@ -1081,7 +1081,6 @@ interface ReadonlyArray<T> {
10811081
* @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.
10821082
*/
10831083
reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: ReadonlyArray<T>) => T): T;
1084-
reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: ReadonlyArray<T>) => T, initialValue: T): T;
10851084
/**
10861085
* 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.
10871086
* @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.
@@ -1094,7 +1093,6 @@ interface ReadonlyArray<T> {
10941093
* @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.
10951094
*/
10961095
reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: ReadonlyArray<T>) => T): T;
1097-
reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: ReadonlyArray<T>) => T, initialValue: T): T;
10981096
/**
10991097
* 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.
11001098
* @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.
@@ -1240,7 +1238,6 @@ interface Array<T> {
12401238
* @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.
12411239
*/
12421240
reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T;
1243-
reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T;
12441241
/**
12451242
* 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.
12461243
* @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.
@@ -1253,7 +1250,6 @@ interface Array<T> {
12531250
* @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.
12541251
*/
12551252
reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T;
1256-
reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T;
12571253
/**
12581254
* 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.
12591255
* @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.
@@ -1721,7 +1717,6 @@ interface Int8Array {
17211717
* instead of an array value.
17221718
*/
17231719
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int8Array) => number): number;
1724-
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int8Array) => number, initialValue: number): number;
17251720

17261721
/**
17271722
* Calls the specified callback function for all the elements in an array. The return value of
@@ -1746,7 +1741,6 @@ interface Int8Array {
17461741
* argument instead of an array value.
17471742
*/
17481743
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int8Array) => number): number;
1749-
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int8Array) => number, initialValue: number): number;
17501744

17511745
/**
17521746
* Calls the specified callback function for all the elements in an array, in descending order.
@@ -1990,7 +1984,6 @@ interface Uint8Array {
19901984
* instead of an array value.
19911985
*/
19921986
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint8Array) => number): number;
1993-
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint8Array) => number, initialValue: number): number;
19941987

19951988
/**
19961989
* Calls the specified callback function for all the elements in an array. The return value of
@@ -2015,7 +2008,6 @@ interface Uint8Array {
20152008
* argument instead of an array value.
20162009
*/
20172010
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint8Array) => number): number;
2018-
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint8Array) => number, initialValue: number): number;
20192011

20202012
/**
20212013
* Calls the specified callback function for all the elements in an array, in descending order.
@@ -2259,7 +2251,6 @@ interface Uint8ClampedArray {
22592251
* instead of an array value.
22602252
*/
22612253
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint8ClampedArray) => number): number;
2262-
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint8ClampedArray) => number, initialValue: number): number;
22632254

22642255
/**
22652256
* Calls the specified callback function for all the elements in an array. The return value of
@@ -2284,7 +2275,6 @@ interface Uint8ClampedArray {
22842275
* argument instead of an array value.
22852276
*/
22862277
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint8ClampedArray) => number): number;
2287-
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint8ClampedArray) => number, initialValue: number): number;
22882278

22892279
/**
22902280
* Calls the specified callback function for all the elements in an array, in descending order.
@@ -2526,7 +2516,6 @@ interface Int16Array {
25262516
* instead of an array value.
25272517
*/
25282518
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int16Array) => number): number;
2529-
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int16Array) => number, initialValue: number): number;
25302519

25312520
/**
25322521
* Calls the specified callback function for all the elements in an array. The return value of
@@ -2551,7 +2540,6 @@ interface Int16Array {
25512540
* argument instead of an array value.
25522541
*/
25532542
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int16Array) => number): number;
2554-
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int16Array) => number, initialValue: number): number;
25552543

25562544
/**
25572545
* Calls the specified callback function for all the elements in an array, in descending order.
@@ -2796,7 +2784,6 @@ interface Uint16Array {
27962784
* instead of an array value.
27972785
*/
27982786
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint16Array) => number): number;
2799-
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint16Array) => number, initialValue: number): number;
28002787

28012788
/**
28022789
* Calls the specified callback function for all the elements in an array. The return value of
@@ -2821,7 +2808,6 @@ interface Uint16Array {
28212808
* argument instead of an array value.
28222809
*/
28232810
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint16Array) => number): number;
2824-
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint16Array) => number, initialValue: number): number;
28252811

28262812
/**
28272813
* Calls the specified callback function for all the elements in an array, in descending order.
@@ -3065,7 +3051,6 @@ interface Int32Array {
30653051
* instead of an array value.
30663052
*/
30673053
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int32Array) => number): number;
3068-
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int32Array) => number, initialValue: number): number;
30693054

30703055
/**
30713056
* Calls the specified callback function for all the elements in an array. The return value of
@@ -3090,7 +3075,6 @@ interface Int32Array {
30903075
* argument instead of an array value.
30913076
*/
30923077
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int32Array) => number): number;
3093-
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int32Array) => number, initialValue: number): number;
30943078

30953079
/**
30963080
* Calls the specified callback function for all the elements in an array, in descending order.
@@ -3333,7 +3317,6 @@ interface Uint32Array {
33333317
* instead of an array value.
33343318
*/
33353319
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint32Array) => number): number;
3336-
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint32Array) => number, initialValue: number): number;
33373320

33383321
/**
33393322
* Calls the specified callback function for all the elements in an array. The return value of
@@ -3358,7 +3341,6 @@ interface Uint32Array {
33583341
* argument instead of an array value.
33593342
*/
33603343
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint32Array) => number): number;
3361-
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint32Array) => number, initialValue: number): number;
33623344

33633345
/**
33643346
* Calls the specified callback function for all the elements in an array, in descending order.
@@ -3602,7 +3584,6 @@ interface Float32Array {
36023584
* instead of an array value.
36033585
*/
36043586
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Float32Array) => number): number;
3605-
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Float32Array) => number, initialValue: number): number;
36063587

36073588
/**
36083589
* Calls the specified callback function for all the elements in an array. The return value of
@@ -3627,7 +3608,6 @@ interface Float32Array {
36273608
* argument instead of an array value.
36283609
*/
36293610
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Float32Array) => number): number;
3630-
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Float32Array) => number, initialValue: number): number;
36313611

36323612
/**
36333613
* Calls the specified callback function for all the elements in an array, in descending order.
@@ -3872,7 +3852,6 @@ interface Float64Array {
38723852
* instead of an array value.
38733853
*/
38743854
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Float64Array) => number): number;
3875-
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Float64Array) => number, initialValue: number): number;
38763855

38773856
/**
38783857
* Calls the specified callback function for all the elements in an array. The return value of
@@ -3897,7 +3876,6 @@ interface Float64Array {
38973876
* argument instead of an array value.
38983877
*/
38993878
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Float64Array) => number): number;
3900-
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Float64Array) => number, initialValue: number): number;
39013879

39023880
/**
39033881
* 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)