mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-08-31 11:40:47 +08:00
Merge pull request #4246 from dbeckwith/underscore-reduce
adds function type for Dictionary version of reduce (issue 4244)
This commit is contained in:
@@ -11,6 +11,7 @@ _.map({ one: 1, two: 2, three: 3 }, (value, key) => value * 3);
|
||||
//var sum = _.reduce([1, 2, 3], (memo, num) => memo + num, 0); // https://typescript.codeplex.com/workitem/1960
|
||||
var sum = _.reduce<number, number>([1, 2, 3], (memo, num) => memo + num, 0);
|
||||
sum = _.reduce<number, number>([1, 2, 3], (memo, num) => memo + num); // memo is optional #issue 5 github
|
||||
sum = _.reduce<string, number>({'a':'1', 'b':'2', 'c':'3'}, (memo, numstr) => memo + (+numstr));
|
||||
|
||||
var list = [[0, 1], [2, 3], [4, 5]];
|
||||
//var flat = _.reduceRight(list, (a, b) => a.concat(b), []); // https://typescript.codeplex.com/workitem/1960
|
||||
|
||||
Vendored
+17
-13
@@ -41,18 +41,6 @@ declare module _ {
|
||||
escape?: RegExp;
|
||||
}
|
||||
|
||||
interface ListIterator<T, TResult> {
|
||||
(value: T, index: number, list: T[]): TResult;
|
||||
}
|
||||
|
||||
interface ObjectIterator<T, TResult> {
|
||||
(element: T, key: string, list: any): TResult;
|
||||
}
|
||||
|
||||
interface MemoIterator<T, TResult> {
|
||||
(prev: TResult, curr: T, index: number, list: T[]): TResult;
|
||||
}
|
||||
|
||||
interface Collection<T> { }
|
||||
|
||||
// Common interface between Arrays and jQuery objects
|
||||
@@ -64,6 +52,22 @@ declare module _ {
|
||||
interface Dictionary<T> extends Collection<T> {
|
||||
[index: string]: T;
|
||||
}
|
||||
|
||||
interface ListIterator<T, TResult> {
|
||||
(value: T, index: number, list: List<T>): TResult;
|
||||
}
|
||||
|
||||
interface ObjectIterator<T, TResult> {
|
||||
(element: T, key: string, list: Dictionary<T>): TResult;
|
||||
}
|
||||
|
||||
interface MemoIterator<T, TResult> {
|
||||
(prev: TResult, curr: T, index: number, list: List<T>): TResult;
|
||||
}
|
||||
|
||||
interface MemoObjectIterator<T, TResult> {
|
||||
(prev: TResult, curr: T, key: string, list: Dictionary<T>): TResult;
|
||||
}
|
||||
}
|
||||
|
||||
interface UnderscoreStatic {
|
||||
@@ -181,7 +185,7 @@ interface UnderscoreStatic {
|
||||
|
||||
reduce<T, TResult>(
|
||||
list: _.Dictionary<T>,
|
||||
iterator: _.ObjectIterator<T, TResult>,
|
||||
iterator: _.MemoObjectIterator<T, TResult>,
|
||||
memo?: TResult,
|
||||
context?: any): TResult;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user