From 1ffa6ceef1821e241fe94a16ae832ed0210187a4 Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Tue, 29 Dec 2015 23:22:59 +0500 Subject: [PATCH] lodash: signatures of _.countBy have been changed --- lodash/lodash-tests.ts | 137 +++++++++++++++++++++++-- lodash/lodash.d.ts | 222 ++++++++++++++++++++++++++++++----------- 2 files changed, 295 insertions(+), 64 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 77a20e2e2..8df7072c2 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -3241,13 +3241,138 @@ module TestContains { } } -result = <_.Dictionary>_.countBy([4.3, 6.1, 6.4], function (num) { return Math.floor(num); }); -result = <_.Dictionary>_.countBy([4.3, 6.1, 6.4], function (num) { return this.floor(num); }, Math); -result = <_.Dictionary>_.countBy(['one', 'two', 'three'], 'length'); +// _.countBy +module TestCountBy { + let array: TResult[]; + let list: _.List; + let dictionary: _.Dictionary; + let numericDictionary: _.NumericDictionary; -result = <_.LoDashImplicitObjectWrapper<_.Dictionary>>_([4.3, 6.1, 6.4]).countBy(function (num) { return Math.floor(num); }); -result = <_.LoDashImplicitObjectWrapper<_.Dictionary>>_([4.3, 6.1, 6.4]).countBy(function (num) { return this.floor(num); }, Math); -result = <_.LoDashImplicitObjectWrapper<_.Dictionary>>_(['one', 'two', 'three']).countBy('length'); + let stringIterator: (value: string, index: number, collection: string) => any; + let listIterator: (value: TResult, index: number, collection: _.List) => any; + let dictionaryIterator: (value: TResult, key: string, collection: _.Dictionary) => any; + let numericDictionaryIterator: (value: TResult, key: number, collection: _.NumericDictionary) => any; + + { + let result: _.Dictionary; + + result = _.countBy(''); + result = _.countBy('', stringIterator); + result = _.countBy('', stringIterator, any); + + result = _.countBy(array); + result = _.countBy(array, listIterator); + result = _.countBy(array, listIterator, any); + result = _.countBy(array, ''); + result = _.countBy(array, '', any); + result = _.countBy<{a: number}, TResult>(array, {a: 42}); + result = _.countBy(array, {a: 42}); + + result = _.countBy(list); + result = _.countBy(list, listIterator); + result = _.countBy(list, listIterator, any); + result = _.countBy(list, ''); + result = _.countBy(list, '', any); + result = _.countBy<{a: number}, TResult>(list, {a: 42}); + result = _.countBy(list, {a: 42}); + + result = _.countBy(dictionary); + result = _.countBy(dictionary, dictionaryIterator); + result = _.countBy(dictionary, dictionaryIterator, any); + result = _.countBy(dictionary, ''); + result = _.countBy(dictionary, '', any); + result = _.countBy<{a: number}, TResult>(dictionary, {a: 42}); + result = _.countBy(dictionary, {a: 42}); + + result = _.countBy(numericDictionary); + result = _.countBy(numericDictionary, numericDictionaryIterator); + result = _.countBy(numericDictionary, numericDictionaryIterator, any); + result = _.countBy(numericDictionary, ''); + result = _.countBy(numericDictionary, '', any); + result = _.countBy<{a: number}, TResult>(numericDictionary, {a: 42}); + result = _.countBy(numericDictionary, {a: 42}); + } + + { + let resutl: _.LoDashImplicitObjectWrapper<_.Dictionary>; + + result = _('').countBy(); + result = _('').countBy(stringIterator); + result = _('').countBy(stringIterator, any); + + result = _(array).countBy(); + result = _(array).countBy(listIterator); + result = _(array).countBy(listIterator, any); + result = _(array).countBy(''); + result = _(array).countBy('', any); + result = _(array).countBy<{a: number}>({a: 42}); + result = _(array).countBy({a: 42}); + + result = _(list).countBy(); + result = _(list).countBy(listIterator); + result = _(list).countBy(listIterator, any); + result = _(list).countBy(''); + result = _(list).countBy('', any); + result = _(list).countBy<{a: number}>({a: 42}); + result = _(list).countBy({a: 42}); + + result = _(dictionary).countBy(); + result = _(dictionary).countBy(dictionaryIterator); + result = _(dictionary).countBy(dictionaryIterator, any); + result = _(dictionary).countBy(''); + result = _(dictionary).countBy('', any); + result = _(dictionary).countBy<{a: number}>({a: 42}); + result = _(dictionary).countBy({a: 42}); + + result = _(numericDictionary).countBy(); + result = _(numericDictionary).countBy(numericDictionaryIterator); + result = _(numericDictionary).countBy(numericDictionaryIterator, any); + result = _(numericDictionary).countBy(''); + result = _(numericDictionary).countBy('', any); + result = _(numericDictionary).countBy<{a: number}>({a: 42}); + result = _(numericDictionary).countBy({a: 42}); + } + + { + let resutl: _.LoDashExplicitObjectWrapper<_.Dictionary>; + + result = _('').chain().countBy(); + result = _('').chain().countBy(stringIterator); + result = _('').chain().countBy(stringIterator, any); + + result = _(array).chain().countBy(); + result = _(array).chain().countBy(listIterator); + result = _(array).chain().countBy(listIterator, any); + result = _(array).chain().countBy(''); + result = _(array).chain().countBy('', any); + result = _(array).chain().countBy<{a: number}>({a: 42}); + result = _(array).chain().countBy({a: 42}); + + result = _(list).chain().countBy(); + result = _(list).chain().countBy(listIterator); + result = _(list).chain().countBy(listIterator, any); + result = _(list).chain().countBy(''); + result = _(list).chain().countBy('', any); + result = _(list).chain().countBy<{a: number}>({a: 42}); + result = _(list).chain().countBy({a: 42}); + + result = _(dictionary).chain().countBy(); + result = _(dictionary).chain().countBy(dictionaryIterator); + result = _(dictionary).chain().countBy(dictionaryIterator, any); + result = _(dictionary).chain().countBy(''); + result = _(dictionary).chain().countBy('', any); + result = _(dictionary).chain().countBy<{a: number}>({a: 42}); + result = _(dictionary).chain().countBy({a: 42}); + + result = _(numericDictionary).chain().countBy(); + result = _(numericDictionary).chain().countBy(numericDictionaryIterator); + result = _(numericDictionary).chain().countBy(numericDictionaryIterator, any); + result = _(numericDictionary).chain().countBy(''); + result = _(numericDictionary).chain().countBy('', any); + result = _(numericDictionary).chain().countBy<{a: number}>({a: 42}); + result = _(numericDictionary).chain().countBy({a: 42}); + } +} // _.detect module TestDetect { diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index c45ec90ee..4320b98ea 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -4913,87 +4913,193 @@ declare module _ { //_.countBy interface LoDashStatic { /** - * Creates an object composed of keys generated from the results of running each element - * of collection through the callback. The corresponding value of each key is the number - * of times the key was returned by the callback. 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. - **/ - countBy( - collection: Array, - callback?: ListIterator, - thisArg?: any): Dictionary; - - /** - * @see _.countBy - * @param callback Function name - **/ + * 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 the number of times the key was returned by iteratee. 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. + */ countBy( collection: List, - callback?: ListIterator, - thisArg?: any): Dictionary; + iteratee?: ListIterator, + thisArg?: any + ): Dictionary; /** - * @see _.countBy - * @param callback Function name - **/ + * @see _.countBy + */ countBy( collection: Dictionary, - callback?: DictionaryIterator, - thisArg?: any): Dictionary; + iteratee?: DictionaryIterator, + thisArg?: any + ): Dictionary; /** - * @see _.countBy - * @param callback Function name - **/ + * @see _.countBy + */ countBy( - collection: Array, - callback: string, - thisArg?: any): Dictionary; + collection: NumericDictionary, + iteratee?: NumericDictionaryIterator, + thisArg?: any + ): Dictionary; /** - * @see _.countBy - * @param callback Function name - **/ + * @see _.countBy + */ countBy( - collection: List, - callback: string, - thisArg?: any): Dictionary; + collection: List|Dictionary|NumericDictionary, + iteratee?: string, + thisArg?: any + ): Dictionary; /** - * @see _.countBy - * @param callback Function name - **/ + * @see _.countBy + */ + countBy( + collection: List|Dictionary|NumericDictionary, + iteratee?: W + ): Dictionary; + + /** + * @see _.countBy + */ countBy( - collection: Dictionary, - callback: string, - thisArg?: any): Dictionary; + collection: List|Dictionary|NumericDictionary, + iteratee?: Object + ): Dictionary; + } + + interface LoDashImplicitWrapper { + /** + * @see _.countBy + */ + countBy( + iteratee?: ListIterator, + thisArg?: any + ): LoDashImplicitObjectWrapper>; } interface LoDashImplicitArrayWrapper { /** - * @see _.countBy - **/ + * @see _.countBy + */ countBy( - callback?: ListIterator, - thisArg?: any): LoDashImplicitObjectWrapper>; + iteratee?: ListIterator, + thisArg?: any + ): LoDashImplicitObjectWrapper>; /** - * @see _.countBy - * @param callback Function name - **/ + * @see _.countBy + */ countBy( - callback: string, - thisArg?: any): LoDashImplicitObjectWrapper>; + iteratee?: string, + thisArg?: any + ): LoDashImplicitObjectWrapper>; + + /** + * @see _.countBy + */ + countBy( + iteratee?: W + ): LoDashImplicitObjectWrapper>; + } + + interface LoDashImplicitObjectWrapper { + /** + * @see _.countBy + */ + countBy( + iteratee?: ListIterator|DictionaryIterator|NumericDictionaryIterator, + thisArg?: any + ): LoDashImplicitObjectWrapper>; + + /** + * @see _.countBy + */ + countBy( + iteratee?: string, + thisArg?: any + ): LoDashImplicitObjectWrapper>; + + /** + * @see _.countBy + */ + countBy( + iteratee?: W + ): LoDashImplicitObjectWrapper>; + } + + interface LoDashExplicitWrapper { + /** + * @see _.countBy + */ + countBy( + iteratee?: ListIterator, + thisArg?: any + ): LoDashExplicitObjectWrapper>; + } + + interface LoDashExplicitArrayWrapper { + /** + * @see _.countBy + */ + countBy( + iteratee?: ListIterator, + thisArg?: any + ): LoDashExplicitObjectWrapper>; + + /** + * @see _.countBy + */ + countBy( + iteratee?: string, + thisArg?: any + ): LoDashExplicitObjectWrapper>; + + /** + * @see _.countBy + */ + countBy( + iteratee?: W + ): LoDashExplicitObjectWrapper>; + } + + interface LoDashExplicitObjectWrapper { + /** + * @see _.countBy + */ + countBy( + iteratee?: ListIterator|DictionaryIterator|NumericDictionaryIterator, + thisArg?: any + ): LoDashExplicitObjectWrapper>; + + /** + * @see _.countBy + */ + countBy( + iteratee?: string, + thisArg?: any + ): LoDashExplicitObjectWrapper>; + + /** + * @see _.countBy + */ + countBy( + iteratee?: W + ): LoDashExplicitObjectWrapper>; } //_.detect