From 6f61e6419b75ab21d222cbe22eaf99ac8fb7bb51 Mon Sep 17 00:00:00 2001 From: Brian Zengel Date: Mon, 16 Jun 2014 14:38:16 -0400 Subject: [PATCH] Add definitions for _.groupBy and _(...).groupBy when passed an object. --- lodash/lodash-tests.ts | 14 +++++++++--- lodash/lodash.d.ts | 51 +++++++++++++++++++++++++++++++++++++++--- 2 files changed, 59 insertions(+), 6 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index bc3727192..cc4ab4408 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -425,9 +425,17 @@ result = <_.Dictionary>_.groupBy([4.2, 6.1, 6.4], function (num) { ret result = <_.Dictionary>_.groupBy([4.2, 6.1, 6.4], function (num) { return this.floor(num); }, Math); result = <_.Dictionary>_.groupBy(['one', 'two', 'three'], 'length'); -result = <_.LoDashObjectWrapper<_.Dictionary>>_([4.2, 6.1, 6.4]).groupBy(function (num) { return Math.floor(num); }); -result = <_.LoDashObjectWrapper<_.Dictionary>>_([4.2, 6.1, 6.4]).groupBy(function (num) { return this.floor(num); }, Math); -result = <_.LoDashObjectWrapper<_.Dictionary>>_(['one', 'two', 'three']).groupBy('length'); +result = <_.Dictionary>_.groupBy({ prop1: 4.2, prop2: 6.1, prop3: 6.4}, function (num) { return Math.floor(num); }); +result = <_.Dictionary>_.groupBy({ prop1: 4.2, prop2: 6.1, prop3: 6.4}, function (num) { return this.floor(num); }, Math); +result = <_.Dictionary>_.groupBy({ prop1: 'one', prop2: 'two', prop3: 'three'}, 'length'); + +result = <_.Dictionary>_([4.2, 6.1, 6.4]).groupBy(function (num) { return Math.floor(num); }).value(); +result = <_.Dictionary>_([4.2, 6.1, 6.4]).groupBy(function (num) { return this.floor(num); }, Math).value(); +result = <_.Dictionary>_(['one', 'two', 'three']).groupBy('length').value(); + +result = <_.Dictionary>_({ prop1: 4.2, prop2: 6.1, prop3: 6.4}).groupBy(function (num) { return Math.floor(num); }).value(); +result = <_.Dictionary>_({ prop1: 4.2, prop2: 6.1, prop3: 6.4}).groupBy(function (num) { return this.floor(num); }, Math).value(); +result = <_.Dictionary>_({ prop1: 'one', prop2: 'two', prop3: 'three'}).groupBy('length').value(); result = <_.Dictionary>_.indexBy(keys, 'dir'); result = <_.Dictionary>_.indexBy(keys, function (key) { return String.fromCharCode(key.code); }); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index e198ebc57..24e55836a 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -3169,6 +3169,30 @@ declare module _ { groupBy( collection: List, whereValue: W): Dictionary; + + /** + * @see _.groupBy + **/ + groupBy( + collection: Dictionary, + callback?: ListIterator, + thisArg?: any): Dictionary; + + /** + * @see _.groupBy + * @param pluckValue _.pluck style callback + **/ + groupBy( + collection: Dictionary, + pluckValue: string): Dictionary; + + /** + * @see _.groupBy + * @param whereValue _.where style callback + **/ + groupBy( + collection: Dictionary, + whereValue: W): Dictionary; } interface LoDashArrayWrapper { @@ -3177,19 +3201,40 @@ declare module _ { **/ groupBy( callback: ListIterator, - thisArg?: any): _.LoDashObjectWrapper>; + thisArg?: any): _.LoDashObjectWrapper<_.Dictionary>; /** * @see _.groupBy **/ groupBy( - pluckValue: string): _.LoDashObjectWrapper>; + pluckValue: string): _.LoDashObjectWrapper<_.Dictionary>; /** * @see _.groupBy **/ groupBy( - whereValue: W): _.LoDashObjectWrapper>; + whereValue: W): _.LoDashObjectWrapper<_.Dictionary>; + } + + interface LoDashObjectWrapper { + /** + * @see _.groupBy + **/ + groupBy( + callback: ListIterator, + thisArg?: any): _.LoDashObjectWrapper<_.Dictionary>; + + /** + * @see _.groupBy + **/ + groupBy( + pluckValue: string): _.LoDashObjectWrapper<_.Dictionary>; + + /** + * @see _.groupBy + **/ + groupBy( + whereValue: W): _.LoDashObjectWrapper<_.Dictionary>; } //_.indexBy