diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index e87da2110d..3caeec9f53 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -39,6 +39,10 @@ interface IKey { code: number; } +interface IDictionary { + [index: string]: T; +} + var foodsOrganic: IFoodOrganic[] = [ { name: 'banana', organic: true }, { name: 'beet', organic: false }, @@ -61,7 +65,10 @@ var stoogesAges: IStoogesAge[] = [ { 'name': 'moe', 'age': 40 }, { 'name': 'larry', 'age': 50 } ]; - +var stoogesAgesDict: IDictionary = { + first: { 'name': 'moe', 'age': 40 }, + second: { 'name': 'larry', 'age': 50 } +}; var stoogesCombined: IStoogesCombined[] = [ { 'name': 'curly', 'age': 30, 'quotes': ['Oh, a wise guy, eh?', 'Poifect!'] }, { 'name': 'moe', 'age': 40, 'quotes': ['Spread out!', 'You knucklehead!'] } @@ -501,6 +508,23 @@ result = <_.LoDashWrapper>_([4, 2, 8, 6]).min(); result = <_.LoDashWrapper>_(stoogesAges).min(function (stooge) { return stooge.age; }); result = <_.LoDashWrapper>_(stoogesAges).min('age'); +result = _.sum([4, 2, 8, 6]); +result = _.sum([4, 2, 8, 6], function(v) { return v; }); +result = _.sum({a: 2, b: 4}); +result = _.sum({a: 2, b: 4}, function(v) { return v; }); +result = _.sum(stoogesAges, function (stooge) { return stooge.age; }); +result = _.sum(stoogesAges, 'age'); +result = _.sum(stoogesAgesDict, function(stooge) { return stooge.age; }); +result = _.sum(stoogesAgesDict, 'age'); +result = _([4, 2, 8, 6]).sum(); +result = _([4, 2, 8, 6]).sum(function(v) { return v; }); +result = _({a: 2, b: 4}).sum(); +result = _({a: 2, b: 4}).sum(function(v) { return v; }); +result = _(stoogesAges).sum(function (stooge) { return stooge.age; }); +result = _(stoogesAges).sum('age'); +result = _(stoogesAgesDict).sum(function (stooge) { return stooge.age; }); +result = _(stoogesAgesDict).sum('age'); + result = _.pluck(stoogesAges, 'name'); result = _(stoogesAges).pluck('name').value(); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index e2878d595b..92ed24ef93 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -41,6 +41,7 @@ declare module _ { (value: number): LoDashWrapper; (value: string): LoDashWrapper; (value: boolean): LoDashWrapper; + (value: Array): LoDashNumberArrayWrapper; (value: Array): LoDashArrayWrapper; (value: T): LoDashObjectWrapper; (value: any): LoDashWrapper; @@ -205,6 +206,8 @@ declare module _ { unshift(...items: any[]): LoDashWrapper; } + interface LoDashNumberArrayWrapper extends LoDashArrayWrapper { } + //_.chain interface LoDashStatic { /** @@ -3842,6 +3845,131 @@ declare module _ { min( whereValue: W): LoDashWrapper; } + + //_.sum + interface LoDashStatic { + /** + * Gets the sum of the values in collection. + * + * @param collection The collection to iterate over. + * @param iteratee The function invoked per iteration. + * @param thisArg The this binding of iteratee. + * @return Returns the sum. + **/ + sum( + collection: Array): number; + + /** + * @see _.sum + **/ + sum( + collection: List): number; + + /** + * @see _.sum + **/ + sum( + collection: Dictionary): number; + + /** + * @see _.sum + **/ + sum( + collection: Array, + iteratee: ListIterator, + thisArg?: any): number; + + /** + * @see _.sum + **/ + sum( + collection: List, + iteratee: ListIterator, + thisArg?: any): number; + + /** + * @see _.sum + **/ + sum( + collection: Dictionary, + iteratee: ObjectIterator, + thisArg?: any): number; + + /** + * @see _.sum + * @param property _.property callback shorthand. + **/ + sum( + collection: Array, + property: string): number; + + /** + * @see _.sum + * @param property _.property callback shorthand. + **/ + sum( + collection: List, + property: string): number; + + /** + * @see _.sum + * @param property _.property callback shorthand. + **/ + sum( + collection: Dictionary, + property: string): number; + } + + interface LoDashNumberArrayWrapper { + /** + * @see _.sum + **/ + sum(): number + + /** + * @see _.sum + **/ + sum( + iteratee: ListIterator, + thisArg?: any): number; + } + + interface LoDashArrayWrapper { + /** + * @see _.sum + **/ + sum( + iteratee: ListIterator, + thisArg?: any): number; + + /** + * @see _.sum + * @param property _.property callback shorthand. + **/ + sum( + property: string): number; + } + + interface LoDashObjectWrapper { + /** + * @see _.sum + **/ + sum(): number + + /** + * @see _.sum + **/ + sum( + iteratee: ObjectIterator, + thisArg?: any): number; + + /** + * @see _.sum + * @param property _.property callback shorthand. + **/ + sum( + property: string): number; + } //_.pluck interface LoDashStatic {