Merge pull request #21820 from aj-r/misc-fixes

lodash: fix partition, pick, and iteratee functions like trim
This commit is contained in:
Mine Starks
2017-12-14 17:08:08 -08:00
committed by GitHub
2 changed files with 184 additions and 41 deletions
+149 -25
View File
@@ -6267,7 +6267,7 @@ declare namespace _ {
partition<T>(
collection: List<T> | null | undefined,
callback: ValueIteratee<T>
): T[][];
): [T[], T[]];
/**
* @see _.partition
@@ -6275,7 +6275,7 @@ declare namespace _ {
partition<T extends object>(
collection: T | null | undefined,
callback: ValueIteratee<T[keyof T]>
): Array<Array<T[keyof T]>>;
): [Array<T[keyof T]>, Array<T[keyof T]>];
}
interface LoDashImplicitWrapper<TValue> {
@@ -6285,7 +6285,7 @@ declare namespace _ {
partition<T>(
this: LoDashImplicitWrapper<List<T> | null | undefined>,
callback: ValueIteratee<T>
): LoDashImplicitWrapper<T[][]>;
): LoDashImplicitWrapper<[T[], T[]]>;
/**
* @see _.partition
@@ -6293,7 +6293,7 @@ declare namespace _ {
partition<T>(
this: LoDashImplicitWrapper<T | null | undefined>,
callback: ValueIteratee<T[keyof T]>
): LoDashImplicitWrapper<Array<Array<T[keyof T]>>>;
): LoDashImplicitWrapper<[Array<T[keyof T]>, Array<T[keyof T]>]>;
}
interface LoDashExplicitWrapper<TValue> {
@@ -6303,7 +6303,7 @@ declare namespace _ {
partition<T>(
this: LoDashExplicitWrapper<List<T> | null | undefined>,
callback: ValueIteratee<T>
): LoDashExplicitWrapper<T[][]>;
): LoDashExplicitWrapper<[T[], T[]]>;
/**
* @see _.partition
@@ -6311,7 +6311,7 @@ declare namespace _ {
partition<T>(
this: LoDashExplicitWrapper<T | null | undefined>,
callback: ValueIteratee<T[keyof T]>
): LoDashExplicitWrapper<Array<Array<T[keyof T]>>>;
): LoDashExplicitWrapper<[Array<T[keyof T]>, Array<T[keyof T]>]>;
}
//_.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<TValue> {
/**
* @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<TValue> {
/**
* @see _.random
*/
random(
max?: number,
floating?: boolean
): LoDashExplicitWrapper<number>;
random(floating?: boolean): LoDashExplicitWrapper<number>;
/**
* @see _.random
*/
random(floating?: boolean): LoDashExplicitWrapper<number>;
random(
max: number,
floating?: boolean
): LoDashExplicitWrapper<number>;
}
/**********
@@ -14408,7 +14426,7 @@ declare namespace _ {
* // => { 'a': 1, 'c': 3 }
*/
pick<T extends object, U extends keyof T>(
object: T | null | undefined,
object: T,
...props: Array<Many<U>>
): Pick<T, U>;
@@ -14426,7 +14444,7 @@ declare namespace _ {
* @see _.pick
*/
pick<T extends object, U extends keyof T>(
this: LoDashImplicitWrapper<T | null | undefined>,
this: LoDashImplicitWrapper<T>,
...props: Array<Many<U>>
): LoDashImplicitWrapper<Pick<T, U>>;
@@ -14444,7 +14462,7 @@ declare namespace _ {
* @see _.pick
*/
pick<T extends object, U extends keyof T>(
this: LoDashExplicitWrapper<T | null | undefined>,
this: LoDashExplicitWrapper<T>,
...props: Array<Many<U>>
): LoDashExplicitWrapper<Pick<T, U>>;
@@ -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<TValue> {
@@ -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<TValue> {
@@ -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<TValue> {
@@ -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<TValue> {
@@ -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<TValue> {
@@ -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 its 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<TValue> {
@@ -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<TValue> {
+35 -16
View File
@@ -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<TResult>;
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<TResult, 'a' | 'b'>;
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<Partial<TResult>>;
result = _(obj).pick<TResult>('a');
result = _(obj).pick<TResult>(0, 'a');
result = _(obj).pick<TResult>(['b', 1], 0, 'a');
result = _(obj1).pick('a');
result = _(obj1).pick(0, 'a');
result = _(obj1).pick(['b', 1], 0, 'a');
}
{
let result: _.LoDashImplicitWrapper<Pick<TResult, 'a' | 'b'>>;
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<Partial<TResult>>;
result = _(obj).chain().pick<TResult>('a');
result = _(obj).chain().pick<TResult>(0, 'a');
result = _(obj).chain().pick<TResult>(['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<Pick<TResult, 'a' | 'b'>>;
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