diff --git a/types/lodash/index.d.ts b/types/lodash/index.d.ts index d5f3430db9..caa92006b8 100644 --- a/types/lodash/index.d.ts +++ b/types/lodash/index.d.ts @@ -6267,7 +6267,7 @@ declare namespace _ { partition( collection: List | null | undefined, callback: ValueIteratee - ): T[][]; + ): [T[], T[]]; /** * @see _.partition @@ -6275,7 +6275,7 @@ declare namespace _ { partition( collection: T | null | undefined, callback: ValueIteratee - ): Array>; + ): [Array, Array]; } interface LoDashImplicitWrapper { @@ -6285,7 +6285,7 @@ declare namespace _ { partition( this: LoDashImplicitWrapper | null | undefined>, callback: ValueIteratee - ): LoDashImplicitWrapper; + ): LoDashImplicitWrapper<[T[], T[]]>; /** * @see _.partition @@ -6293,7 +6293,7 @@ declare namespace _ { partition( this: LoDashImplicitWrapper, callback: ValueIteratee - ): LoDashImplicitWrapper>>; + ): LoDashImplicitWrapper<[Array, Array]>; } interface LoDashExplicitWrapper { @@ -6303,7 +6303,7 @@ declare namespace _ { partition( this: LoDashExplicitWrapper | null | undefined>, callback: ValueIteratee - ): LoDashExplicitWrapper; + ): LoDashExplicitWrapper<[T[], T[]]>; /** * @see _.partition @@ -6311,7 +6311,7 @@ declare namespace _ { partition( this: LoDashExplicitWrapper, callback: ValueIteratee - ): LoDashExplicitWrapper>>; + ): LoDashExplicitWrapper<[Array, Array]>; } //_.reduce @@ -11672,8 +11672,6 @@ declare namespace _ { * @return Returns the random number. */ random( - min?: number, - max?: number, floating?: boolean ): number; @@ -11681,44 +11679,64 @@ declare namespace _ { * @see _.random */ random( - min?: number, + max: number, floating?: boolean ): number; /** * @see _.random */ - random(floating?: boolean): number; + random( + min: number, + max: number, + floating?: boolean + ): number; + + /** + * Produces a random number between min and max (inclusive). If only one argument is provided a number between + * 0 and the given number is returned. If floating is true, or either min or max are floats, a floating-point + * number is returned instead of an integer. + * + * @param min The minimum possible value. + * @param index Not used in this overload. + * @param guard Enables use as an iteratee for methods like _.map. You should not pass this parameter directly in your code. + * @return Returns the random number. + */ + random( + min: number, + index: string | number, + guard: object + ): number; } interface LoDashImplicitWrapper { /** * @see _.random */ - random( - max?: number, - floating?: boolean - ): number; + random(floating?: boolean): number; /** * @see _.random */ - random(floating?: boolean): number; + random( + max: number, + floating?: boolean + ): number; } interface LoDashExplicitWrapper { /** * @see _.random */ - random( - max?: number, - floating?: boolean - ): LoDashExplicitWrapper; + random(floating?: boolean): LoDashExplicitWrapper; /** * @see _.random */ - random(floating?: boolean): LoDashExplicitWrapper; + random( + max: number, + floating?: boolean + ): LoDashExplicitWrapper; } /********** @@ -14408,7 +14426,7 @@ declare namespace _ { * // => { 'a': 1, 'c': 3 } */ pick( - object: T | null | undefined, + object: T, ...props: Array> ): Pick; @@ -14426,7 +14444,7 @@ declare namespace _ { * @see _.pick */ pick( - this: LoDashImplicitWrapper, + this: LoDashImplicitWrapper, ...props: Array> ): LoDashImplicitWrapper>; @@ -14444,7 +14462,7 @@ declare namespace _ { * @see _.pick */ pick( - this: LoDashExplicitWrapper, + this: LoDashExplicitWrapper, ...props: Array> ): LoDashExplicitWrapper>; @@ -15681,6 +15699,9 @@ declare namespace _ { * * Note: This method is based on String#split. * + * @param string The string to trim. + * @param separator The separator pattern to split by. + * @param limit The length to truncate results to. * @return Returns the new array of string segments. */ split( @@ -15688,6 +15709,22 @@ declare namespace _ { separator?: RegExp|string, limit?: number ): string[]; + + /** + * Splits string by separator. + * + * Note: This method is based on String#split. + * + * @param string The string to trim. + * @param index Not used in this overload. + * @param guard Enables use as an iteratee for methods like _.map. You should not pass this parameter directly in your code. + * @return Returns the new array of string segments. + */ + split( + string: string, + index: string | number, + guard: object + ): string[]; } interface LoDashImplicitWrapper { @@ -15895,6 +15932,20 @@ declare namespace _ { string?: string, chars?: string ): string; + + /** + * Removes leading and trailing whitespace or specified characters from string. + * + * @param string The string to trim. + * @param index Not used in this overload. + * @param guard Enables use as an iteratee for methods like _.map. You should not pass this parameter directly in your code. + * @return Returns the trimmed string. + */ + trim( + string: string, + index: string | number, + guard: object + ): string; } interface LoDashImplicitWrapper { @@ -15924,6 +15975,20 @@ declare namespace _ { string?: string, chars?: string ): string; + + /** + * Removes trailing whitespace or specified characters from string. + * + * @param string The string to trim. + * @param index Not used in this overload. + * @param guard Enables use as an iteratee for methods like _.map. You should not pass this parameter directly in your code. + * @return Returns the trimmed string. + */ + trimEnd( + string: string, + index: string | number, + guard: object + ): string; } interface LoDashImplicitWrapper { @@ -15953,6 +16018,20 @@ declare namespace _ { string?: string, chars?: string ): string; + + /** + * Removes leading whitespace or specified characters from string. + * + * @param string The string to trim. + * @param index Not used in this overload. + * @param guard Enables use as an iteratee for methods like _.map. You should not pass this parameter directly in your code. + * @return Returns the trimmed string. + */ + trimStart( + string: string, + index: string | number, + guard: object + ): string; } interface LoDashImplicitWrapper { @@ -16100,6 +16179,20 @@ declare namespace _ { string?: string, pattern?: string|RegExp ): string[]; + + /** + * Splits `string` into an array of its words. + * + * @param string The string to inspect. + * @param index Not used in this overload. + * @param guard Enables use as an iteratee for methods like _.map. You should not pass this parameter directly in your code. + * @return Returns the words of `string`. + */ + words( + string: string, + index: string | number, + guard: object + ): string[]; } interface LoDashImplicitWrapper { @@ -16760,6 +16853,22 @@ declare namespace _ { end?: number, step?: number ): number[]; + + /** + * Creates an array of numbers (positive and/or negative) progressing from start up to, but not including, end. + * If end is not specified it’s set to start with start then set to 0. If end is less than start a zero-length + * range is created unless a negative step is specified. + * + * @param start The start of the range. + * @param index Not used in this overload. + * @param guard Enables use as an iteratee for methods like _.map. You should not pass this parameter directly in your code. + * @return Returns a new range array. + */ + range( + end: number, + index: string | number, + guard: object + ): number[]; } interface LoDashImplicitWrapper { @@ -16789,9 +16898,9 @@ declare namespace _ { * descending order. * * @category Util - * @param [start=0] The start of the range. + * @param start The start of the range. * @param end The end of the range. - * @param [step=1] The value to increment or decrement by. + * @param step The value to increment or decrement by. * @returns Returns the new array of numbers. * @example * @@ -16821,6 +16930,21 @@ declare namespace _ { end?: number, step?: number ): number[]; + + /** + * This method is like _.range except that it populates values in + * descending order. + * + * @param start The start of the range. + * @param index Not used in this overload. + * @param guard Enables use as an iteratee for methods like _.map. You should not pass this parameter directly in your code. + * @return Returns a new range array. + */ + rangeRight( + end: number, + index: string | number, + guard: object + ): number[]; } interface LoDashImplicitWrapper { diff --git a/types/lodash/lodash-tests.ts b/types/lodash/lodash-tests.ts index e62d4cbd2d..774e58ef9f 100644 --- a/types/lodash/lodash-tests.ts +++ b/types/lodash/lodash-tests.ts @@ -9866,6 +9866,9 @@ namespace TestRandom { result = _(1).chain().random(true); result = _(true).chain().random(); } + + // $ExpectType number[] + _.map([5, 5], _.random); } /********** @@ -11813,50 +11816,51 @@ namespace TestOmitBy { // _.pick namespace TestPick { - let obj: TResult | null | undefined = any; + let obj1: TResult | null | undefined = any; + let obj2: TResult = any; { let result: Partial; - result = _.pick(obj, 'a'); - result = _.pick(obj, 0, 'a'); - result = _.pick(obj, ['b', 1], 0, 'a'); + result = _.pick(obj1, 'a'); + result = _.pick(obj1, 0, 'a'); + result = _.pick(obj1, ['b', 1], 0, 'a'); } { let result: Pick; - result = _.pick(obj, 'a', 'b'); - result = _.pick(obj, ['a' as 'a', 'b' as 'b']); + result = _.pick(obj2, 'a', 'b'); + result = _.pick(obj2, ['a' as 'a', 'b' as 'b']); } { let result: _.LoDashImplicitWrapper>; - result = _(obj).pick('a'); - result = _(obj).pick(0, 'a'); - result = _(obj).pick(['b', 1], 0, 'a'); + result = _(obj1).pick('a'); + result = _(obj1).pick(0, 'a'); + result = _(obj1).pick(['b', 1], 0, 'a'); } { let result: _.LoDashImplicitWrapper>; - result = _(obj).pick('a', 'b'); - result = _(obj).pick(['a' as 'a', 'b' as 'b']); + result = _(obj2).pick('a', 'b'); + result = _(obj2).pick(['a' as 'a', 'b' as 'b']); } { let result: _.LoDashExplicitWrapper>; - result = _(obj).chain().pick('a'); - result = _(obj).chain().pick(0, 'a'); - result = _(obj).chain().pick(['b', 1], 0, 'a'); + result = _(obj1).chain().pick('a'); + result = _(obj1).chain().pick(0, 'a'); + result = _(obj1).chain().pick(['b', 1], 0, 'a'); } { let result: _.LoDashExplicitWrapper>; - result = _(obj).chain().pick('a', 'b'); - result = _(obj).chain().pick(['a' as 'a', 'b' as 'b']); + result = _(obj2).chain().pick('a', 'b'); + result = _(obj2).chain().pick(['a' as 'a', 'b' as 'b']); } } @@ -12759,6 +12763,9 @@ namespace TestSplit { result = _('a-b-c').chain().split('-'); result = _('a-b-c').chain().split('-', 2); } + + // $ExpectType string[][] + _.map(['abc', 'def'], _.split); } // _.startCase @@ -12882,6 +12889,9 @@ namespace TestTrim { result = _('-_-abc-_-').chain().trim(); result = _('-_-abc-_-').chain().trim('_-'); } + + // $ExpectType string[] + _.map([' foo ', ' bar '], _.trim); } // _.trimEnd @@ -13018,6 +13028,9 @@ namespace TestWords { result = _('fred, barney, & pebbles').chain().words(); result = _('fred, barney, & pebbles').chain().words(/[^, ]+/g); } + + // $ExpectType string[][] + _.map(['fred, barney', 'pebbles'], _.words); } /*********** @@ -13836,6 +13849,9 @@ namespace TestRange { result = _(1).chain().range(11); result = _(0).chain().range(30, 5); } + + // $ExpectType number[][] + _.map([5, 5], _.range); } // _.rangeRight @@ -13863,6 +13879,9 @@ namespace TestRangeRight { result = _(1).chain().rangeRight(11); result = _(0).chain().rangeRight(30, 5); } + + // $ExpectType number[][] + _.map([5, 5], _.rangeRight); } // _.runInContext