diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 7dd2249c9d..fbaded0981 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -1633,13 +1633,6 @@ result = _(0.046).floor(2); result = _(4060).floor(-2); // → 4000 -result = _.max([4, 2, 8, 6]); -result = _.max(stoogesAges, function (stooge) { return stooge.age; }); -result = _.max(stoogesAges, 'age'); -result = <_.LoDashWrapper>_([4, 2, 8, 6]).max(); -result = <_.LoDashWrapper>_(stoogesAges).max(function (stooge) { return stooge.age; }); -result = <_.LoDashWrapper>_(stoogesAges).max('age'); - result = _.min([4, 2, 8, 6]); result = _.min(stoogesAges, function (stooge) { return stooge.age; }); result = _.min(stoogesAges, 'age'); @@ -2424,6 +2417,54 @@ result = _({}).toPlainObject(); result = _.add(1, 1); result = _(1).add(1); +// _.max +module TestMax { + let array: number[]; + let list: _.List; + let dictionary: _.Dictionary; + + let listIterator: (value: number, index: number, collection: _.List) => number; + let dictionaryIterator: (value: number, key: string, collection: _.Dictionary) => number; + + let result: number; + + result = _.max(array); + result = _.max(array, listIterator); + result = _.max(array, listIterator, any); + result = _.max(array, ''); + result = _.max<{a: number}, number>(array, {a: 42}); + + result = _.max(list); + result = _.max(list, listIterator); + result = _.max(list, listIterator, any); + result = _.max(list, ''); + result = _.max<{a: number}, number>(list, {a: 42}); + + result = _.max(dictionary); + result = _.max(dictionary, dictionaryIterator); + result = _.max(dictionary, dictionaryIterator, any); + result = _.max(dictionary, ''); + result = _.max<{a: number}, number>(dictionary, {a: 42}); + + result = _(array).max(); + result = _(array).max(listIterator); + result = _(array).max(listIterator, any); + result = _(array).max(''); + result = _(array).max<{a: number}>({a: 42}); + + result = _(list).max(); + result = _(list).max(listIterator); + result = _(list).max(listIterator, any); + result = _(list).max(''); + result = _(list).max<{a: number}, number>({a: 42}); + + result = _(dictionary).max(); + result = _(dictionary).max(dictionaryIterator); + result = _(dictionary).max(dictionaryIterator, any); + result = _(dictionary).max(''); + result = _(dictionary).max<{a: number}, number>({a: 42}); +} + /********** * Number * **********/ diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 60aaf60b71..b2fc4d6ea5 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -4375,117 +4375,6 @@ declare module _ { floor(precision?: number): number; } - //_.max - interface LoDashStatic { - /** - * Retrieves the maximum value of a collection. If the collection is empty or falsey -Infinity is - * returned. If a callback is provided it will be executed for each value in the collection to - * generate the criterion by which the value is ranked. The callback is bound to thisArg and invoked - * with three arguments; (value, index, 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 maximum value. - **/ - max( - collection: Array, - callback?: ListIterator, - thisArg?: any): T; - - /** - * @see _.max - **/ - max( - collection: List, - callback?: ListIterator, - thisArg?: any): T; - - /** - * @see _.max - **/ - max( - collection: Dictionary, - callback?: DictionaryIterator, - thisArg?: any): T; - - /** - * @see _.max - * @param pluckValue _.pluck style callback - **/ - max( - collection: Array, - pluckValue: string): T; - - /** - * @see _.max - * @param pluckValue _.pluck style callback - **/ - max( - collection: List, - pluckValue: string): T; - - /** - * @see _.max - * @param pluckValue _.pluck style callback - **/ - max( - collection: Dictionary, - pluckValue: string): T; - - /** - * @see _.max - * @param whereValue _.where style callback - **/ - max( - collection: Array, - whereValue: W): T; - - /** - * @see _.max - * @param whereValue _.where style callback - **/ - max( - collection: List, - whereValue: W): T; - - /** - * @see _.max - * @param whereValue _.where style callback - **/ - max( - collection: Dictionary, - whereValue: W): T; - } - - interface LoDashArrayWrapper { - /** - * @see _.max - **/ - max( - callback?: ListIterator, - thisArg?: any): LoDashWrapper; - - /** - * @see _.max - * @param pluckValue _.pluck style callback - **/ - max( - pluckValue: string): LoDashWrapper; - - /** - * @see _.max - * @param whereValue _.where style callback - **/ - max( - whereValue: W): LoDashWrapper; - } - //_.min interface LoDashStatic { /** @@ -7208,6 +7097,110 @@ declare module _ { add(addend: number): number; } + //_.max + interface LoDashStatic { + /** + * Gets the maximum value of collection. If collection is empty or falsey -Infinity is returned. If an iteratee + * function is provided it’s invoked for each value in collection to generate the criterion by which the value + * is ranked. The iteratee is bound to thisArg and invoked with three arguments: (value, index, 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 maximum value. + */ + max( + collection: List, + iteratee?: ListIterator, + thisArg?: any + ): T; + + /** + * @see _.max + */ + max( + collection: Dictionary, + iteratee?: DictionaryIterator, + thisArg?: any + ): T; + + /** + * @see _.max + */ + max( + collection: List|Dictionary, + iteratee?: string, + thisArg?: any + ): T; + + /** + * @see _.max + */ + max( + collection: List|Dictionary, + whereValue?: TObject + ): T; + } + + interface LoDashArrayWrapper { + /** + * @see _.max + */ + max( + iteratee?: ListIterator, + thisArg?: any + ): T; + + /** + * @see _.max + */ + max( + iteratee?: string, + thisArg?: any + ): T; + + /** + * @see _.max + */ + max( + whereValue?: TObject + ): T; + } + + interface LoDashObjectWrapper { + /** + * @see _.max + */ + max( + iteratee?: ListIterator|DictionaryIterator, + thisArg?: any + ): T; + + /** + * @see _.max + */ + max( + iteratee?: string, + thisArg?: any + ): T; + + /** + * @see _.max + */ + max( + whereValue?: TObject + ): T; + } + /********** * Number * **********/