From 6ffb4bca1df52db232db2d7ae42925bab79fcfd8 Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Tue, 1 Dec 2015 05:15:56 +0500 Subject: [PATCH] lodash: signatures of _.groupBy have been changed --- lodash/lodash-tests.ts | 157 ++++++++++++++++++-- lodash/lodash.d.ts | 321 ++++++++++++++++++++++++++++------------- 2 files changed, 369 insertions(+), 109 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index bdc08ccdc7..428f38fbdd 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -3396,21 +3396,154 @@ module TestForEachRight { } } -result = <_.Dictionary>_.groupBy([4.2, 6.1, 6.4], function (num) { return Math.floor(num); }); -result = <_.Dictionary>_.groupBy([4.2, 6.1, 6.4], function (num) { return this.floor(num); }, Math); -result = <_.Dictionary>_.groupBy(['one', 'two', 'three'], 'length'); +// _.groupBy +module TestGroupBy { + type SampleType = {a: number; b: string; c: boolean;}; -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'); + let array: SampleType[]; + let list: _.List; + let dictionary: _.Dictionary; -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(); + let stringIterator: (char: string, index: number, string: string) => number; + let listIterator: (value: SampleType, index: number, collection: _.List) => number; + let dictionaryIterator: (value: SampleType, key: string, collection: _.Dictionary) => number; -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(); + { + let result: _.Dictionary; + + result = _.groupBy(''); + result = _.groupBy('', stringIterator); + result = _.groupBy('', stringIterator, any); + result = _.groupBy('', stringIterator); + result = _.groupBy('', stringIterator, any); + } + + { + let result: _.Dictionary; + + result = _.groupBy(array); + result = _.groupBy(array, listIterator); + result = _.groupBy(array, listIterator, any); + result = _.groupBy(array, ''); + result = _.groupBy(array, '', any); + result = _.groupBy(array, {a: 42}); + + result = _.groupBy(array, listIterator); + result = _.groupBy(array, listIterator, any); + result = _.groupBy(array, '', true); + result = _.groupBy<{a: number}, SampleType>(array, {a: 42}); + + result = _.groupBy(list); + result = _.groupBy(list, listIterator); + result = _.groupBy(list, listIterator, any); + result = _.groupBy(list, ''); + result = _.groupBy(list, '', any); + result = _.groupBy(list, {a: 42}); + + result = _.groupBy(list, listIterator); + result = _.groupBy(list, listIterator, any); + result = _.groupBy(list, '', true); + result = _.groupBy<{a: number}, SampleType>(list, {a: 42}); + + result = _.groupBy(dictionary); + result = _.groupBy(dictionary, dictionaryIterator); + result = _.groupBy(dictionary, dictionaryIterator, any); + result = _.groupBy(dictionary, ''); + result = _.groupBy(dictionary, '', any); + result = _.groupBy(dictionary, {a: 42}); + + result = _.groupBy(dictionary, dictionaryIterator); + result = _.groupBy(dictionary, dictionaryIterator, any); + result = _.groupBy(dictionary, '', true); + result = _.groupBy<{a: number}, SampleType>(dictionary, {a: 42}); + } + + { + let result: _.LoDashImplicitObjectWrapper<_.Dictionary>; + + result = _('').groupBy(); + result = _('').groupBy(stringIterator); + result = _('').groupBy(stringIterator, any); + } + + { + let result: _.LoDashImplicitObjectWrapper<_.Dictionary>; + + result = _(array).groupBy(); + result = _(array).groupBy(listIterator); + result = _(array).groupBy(listIterator, any); + result = _(array).groupBy(''); + result = _(array).groupBy('', true); + result = _(array).groupBy<{a: number}>({a: 42}); + + result = _(list).groupBy(); + result = _(list).groupBy(listIterator); + result = _(list).groupBy(listIterator, any); + result = _(list).groupBy(''); + result = _(list).groupBy('', any); + result = _(list).groupBy({a: 42}); + + result = _(list).groupBy(listIterator); + result = _(list).groupBy(listIterator, any); + result = _(list).groupBy('', true); + result = _(list).groupBy<{a: number}, SampleType>({a: 42}); + + result = _(dictionary).groupBy(); + result = _(dictionary).groupBy(dictionaryIterator); + result = _(dictionary).groupBy(dictionaryIterator, any); + result = _(dictionary).groupBy(''); + result = _(dictionary).groupBy('', any); + result = _(dictionary).groupBy({a: 42}); + + result = _(dictionary).groupBy(dictionaryIterator); + result = _(dictionary).groupBy(dictionaryIterator, any); + result = _(dictionary).groupBy('', true); + result = _(dictionary).groupBy<{a: number}, SampleType>({a: 42}); + } + + { + let result: _.LoDashExplicitObjectWrapper<_.Dictionary>; + + result = _('').chain().groupBy(); + result = _('').chain().groupBy(stringIterator); + result = _('').chain().groupBy(stringIterator, any); + } + + { + let result: _.LoDashExplicitObjectWrapper<_.Dictionary>; + + result = _(array).chain().groupBy(); + result = _(array).chain().groupBy(listIterator); + result = _(array).chain().groupBy(listIterator, any); + result = _(array).chain().groupBy(''); + result = _(array).chain().groupBy('', true); + result = _(array).chain().groupBy<{a: number}>({a: 42}); + + result = _(list).chain().groupBy(); + result = _(list).chain().groupBy(listIterator); + result = _(list).chain().groupBy(listIterator, any); + result = _(list).chain().groupBy(''); + result = _(list).chain().groupBy('', any); + result = _(list).chain().groupBy({a: 42}); + + result = _(list).chain().groupBy(listIterator); + result = _(list).chain().groupBy(listIterator, any); + result = _(list).chain().groupBy('', true); + result = _(list).chain().groupBy<{a: number}, SampleType>({a: 42}); + + result = _(dictionary).chain().groupBy(); + result = _(dictionary).chain().groupBy(dictionaryIterator); + result = _(dictionary).chain().groupBy(dictionaryIterator, any); + result = _(dictionary).chain().groupBy(''); + result = _(dictionary).chain().groupBy('', any); + result = _(dictionary).chain().groupBy({a: 42}); + + result = _(dictionary).chain().groupBy(dictionaryIterator); + result = _(dictionary).chain().groupBy(dictionaryIterator, any); + result = _(dictionary).chain().groupBy('', true); + result = _(dictionary).chain().groupBy<{a: number}, SampleType>({a: 42}); + } +} // _.include module TestInclude { diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index ad465c5c39..bc47a062c4 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -5291,130 +5291,257 @@ declare module _ { //_.groupBy interface LoDashStatic { /** - * Creates an object composed of keys generated from the results of running each element - * of a collection through the callback. The corresponding value of each key is an array - * of the elements responsible for generating the key. The callback is bound to thisArg - * and invoked with three arguments; (value, index|key, collection). - * - * If a property name is provided for callback the created "_.pluck" style callback will - * return the property value of the given element. - * If an object is provided for callback the created "_.where" style callback will return - * true for elements that have the properties of the given object, else false - * @param collection The collection to iterate over. - * @param callback The function called per iteration. - * @param thisArg The this binding of callback. - * @return Returns the composed aggregate object. - **/ - groupBy( - collection: Array, - callback?: ListIterator, - thisArg?: any): Dictionary; - - /** - * @see _.groupBy - **/ - groupBy( + * Creates an object composed of keys generated from the results of running each element of collection through + * iteratee. The corresponding value of each key is an array of the elements responsible for generating the + * key. The iteratee is bound to thisArg and invoked with three arguments: + * (value, index|key, collection). + * + * If a property name is provided for iteratee the created _.property style callback returns the property + * value of the given element. + * + * If a value is also provided for thisArg the created _.matchesProperty style callback returns true for + * elements that have a matching property value, else false. + * + * If an object is provided for iteratee the created _.matches style callback returns true for elements that + * have the properties of the given object, else false. + * + * @param collection The collection to iterate over. + * @param iteratee The function invoked per iteration. + * @param thisArg The this binding of iteratee. + * @return Returns the composed aggregate object. + */ + groupBy( collection: List, - callback?: ListIterator, - thisArg?: any): Dictionary; + iteratee?: ListIterator, + thisArg?: any + ): Dictionary; /** - * @see _.groupBy - * @param pluckValue _.pluck style callback - **/ + * @see _.groupBy + */ groupBy( - collection: Array, - pluckValue: string): Dictionary; + collection: List, + iteratee?: ListIterator, + thisArg?: any + ): Dictionary; /** - * @see _.groupBy - * @param pluckValue _.pluck style callback - **/ - groupBy( - collection: List, - pluckValue: string): Dictionary; - - /** - * @see _.groupBy - * @param whereValue _.where style callback - **/ - groupBy( - collection: Array, - whereValue: W): Dictionary; - - /** - * @see _.groupBy - * @param whereValue _.where style callback - **/ - groupBy( - collection: List, - whereValue: W): Dictionary; - - /** - * @see _.groupBy - **/ - groupBy( + * @see _.groupBy + */ + groupBy( collection: Dictionary, - callback?: DictionaryIterator, - thisArg?: any): Dictionary; + iteratee?: DictionaryIterator, + thisArg?: any + ): Dictionary; /** - * @see _.groupBy - * @param pluckValue _.pluck style callback - **/ - groupBy( - collection: Dictionary, - pluckValue: string): Dictionary; + * @see _.groupBy + */ + groupBy( + collection: Dictionary, + iteratee?: DictionaryIterator, + thisArg?: any + ): Dictionary; /** - * @see _.groupBy - * @param whereValue _.where style callback - **/ - groupBy( - collection: Dictionary, - whereValue: W): Dictionary; + * @see _.groupBy + */ + groupBy( + collection: List|Dictionary, + iteratee?: string, + thisArg?: TValue + ): Dictionary; + + /** + * @see _.groupBy + */ + groupBy( + collection: List|Dictionary, + iteratee?: string, + thisArg?: any + ): Dictionary; + + /** + * @see _.groupBy + */ + groupBy( + collection: List|Dictionary, + iteratee?: TWhere + ): Dictionary; + + /** + * @see _.groupBy + */ + groupBy( + collection: List|Dictionary, + iteratee?: Object + ): Dictionary; + } + + interface LoDashImplicitWrapper { + /** + * @see _.groupBy + */ + groupBy( + iteratee?: ListIterator, + thisArg?: any + ): LoDashImplicitObjectWrapper>; } interface LoDashImplicitArrayWrapper { /** - * @see _.groupBy - **/ - groupBy( - callback: ListIterator, - thisArg?: any): _.LoDashImplicitObjectWrapper<_.Dictionary>; + * @see _.groupBy + */ + groupBy( + iteratee?: ListIterator, + thisArg?: any + ): LoDashImplicitObjectWrapper>; /** - * @see _.groupBy - **/ - groupBy( - pluckValue: string): _.LoDashImplicitObjectWrapper<_.Dictionary>; + * @see _.groupBy + */ + groupBy( + iteratee?: string, + thisArg?: TValue + ): LoDashImplicitObjectWrapper>; /** - * @see _.groupBy - **/ - groupBy( - whereValue: W): _.LoDashImplicitObjectWrapper<_.Dictionary>; + * @see _.groupBy + */ + groupBy( + iteratee?: TWhere + ): LoDashImplicitObjectWrapper>; } interface LoDashImplicitObjectWrapper { /** - * @see _.groupBy - **/ - groupBy( - callback: ListIterator, - thisArg?: any): _.LoDashImplicitObjectWrapper<_.Dictionary>; + * @see _.groupBy + */ + groupBy( + iteratee?: ListIterator|DictionaryIterator, + thisArg?: any + ): LoDashImplicitObjectWrapper>; /** - * @see _.groupBy - **/ - groupBy( - pluckValue: string): _.LoDashImplicitObjectWrapper<_.Dictionary>; + * @see _.groupBy + */ + groupBy( + iteratee?: ListIterator|DictionaryIterator, + thisArg?: any + ): LoDashImplicitObjectWrapper>; /** - * @see _.groupBy - **/ - groupBy( - whereValue: W): _.LoDashImplicitObjectWrapper<_.Dictionary>; + * @see _.groupBy + */ + groupBy( + iteratee?: string, + thisArg?: TValue + ): LoDashImplicitObjectWrapper>; + + /** + * @see _.groupBy + */ + groupBy( + iteratee?: string, + thisArg?: any + ): LoDashImplicitObjectWrapper>; + + /** + * @see _.groupBy + */ + groupBy( + iteratee?: TWhere + ): LoDashImplicitObjectWrapper>; + + /** + * @see _.groupBy + */ + groupBy( + iteratee?: Object + ): LoDashImplicitObjectWrapper>; + } + + interface LoDashExplicitWrapper { + /** + * @see _.groupBy + */ + groupBy( + iteratee?: ListIterator, + thisArg?: any + ): LoDashExplicitObjectWrapper>; + } + + interface LoDashExplicitArrayWrapper { + /** + * @see _.groupBy + */ + groupBy( + iteratee?: ListIterator, + thisArg?: any + ): LoDashExplicitObjectWrapper>; + + /** + * @see _.groupBy + */ + groupBy( + iteratee?: string, + thisArg?: TValue + ): LoDashExplicitObjectWrapper>; + + /** + * @see _.groupBy + */ + groupBy( + iteratee?: TWhere + ): LoDashExplicitObjectWrapper>; + } + + interface LoDashExplicitObjectWrapper { + /** + * @see _.groupBy + */ + groupBy( + iteratee?: ListIterator|DictionaryIterator, + thisArg?: any + ): LoDashExplicitObjectWrapper>; + + /** + * @see _.groupBy + */ + groupBy( + iteratee?: ListIterator|DictionaryIterator, + thisArg?: any + ): LoDashExplicitObjectWrapper>; + + /** + * @see _.groupBy + */ + groupBy( + iteratee?: string, + thisArg?: TValue + ): LoDashExplicitObjectWrapper>; + + /** + * @see _.groupBy + */ + groupBy( + iteratee?: string, + thisArg?: any + ): LoDashExplicitObjectWrapper>; + + /** + * @see _.groupBy + */ + groupBy( + iteratee?: TWhere + ): LoDashExplicitObjectWrapper>; + + /** + * @see _.groupBy + */ + groupBy( + iteratee?: Object + ): LoDashExplicitObjectWrapper>; } //_.include