mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-06 09:19:08 +00:00
lodash: changed signatures of the method _.takeWhile
This commit is contained in:
@@ -344,16 +344,6 @@ module TestFirst {
|
||||
result = _(list).first<TResult>();
|
||||
}
|
||||
|
||||
result = <number[]>_.takeWhile([1, 2, 3], (num) => num < 3);
|
||||
result = <boolean[]>_.takeWhile(foodsOrganic, 'organic');
|
||||
result = <IFoodType[]>_.takeWhile(foodsType, { 'type': 'fruit' });
|
||||
|
||||
result = <number[]>_([1, 2, 3]).takeWhile(function (num) {
|
||||
return num < 3;
|
||||
}).value();
|
||||
result = <boolean[]>_(foodsType).takeWhile('organic').value();
|
||||
result = <IFoodType[]>_(foodsType).takeWhile({ 'type': 'fruit' }).value();
|
||||
|
||||
result = <Array<number>>_.flatten([[1, 2], [3, 4]]);
|
||||
result = <Array<number>>_.flatten([[1, 2], [3, 4], 5, 6]);
|
||||
result = <Array<number|Array<Array<number>>>>_.flatten([1, [2], [3, [[4]]]]);
|
||||
@@ -648,6 +638,42 @@ module TestTakeRightWhile {
|
||||
result = _(list).takeRightWhile<{a: number;}, TResult>({a: 42}).value();
|
||||
}
|
||||
|
||||
// _.takeWhile
|
||||
module TestTakeWhile {
|
||||
let array: TResult[];
|
||||
let list: _.List<TResult>;
|
||||
let predicateFn: (value: TResult, index: number, collection: _.List<TResult>) => boolean;
|
||||
let result: TResult[];
|
||||
|
||||
result = _.takeWhile<TResult>(array);
|
||||
result = _.takeWhile<TResult>(array, predicateFn);
|
||||
result = _.takeWhile<TResult>(array, predicateFn, any);
|
||||
result = _.takeWhile<TResult>(array, '')
|
||||
result = _.takeWhile<TResult>(array, '', any);
|
||||
result = _.takeWhile<{a: number;}, TResult>(array, {a: 42});
|
||||
|
||||
result = _.takeWhile<TResult>(list);
|
||||
result = _.takeWhile<TResult>(list, predicateFn);
|
||||
result = _.takeWhile<TResult>(list, predicateFn, any);
|
||||
result = _.takeWhile<TResult>(list, '')
|
||||
result = _.takeWhile<TResult>(list, '', any);
|
||||
result = _.takeWhile<{a: number;}, TResult>(list, {a: 42});
|
||||
|
||||
result = _(array).takeWhile().value();
|
||||
result = _(array).takeWhile(predicateFn).value();
|
||||
result = _(array).takeWhile(predicateFn, any).value();
|
||||
result = _(array).takeWhile('').value();
|
||||
result = _(array).takeWhile('', any).value();
|
||||
result = _(array).takeWhile<{a: number;}>({a: 42}).value();
|
||||
|
||||
result = _(list).takeWhile<TResult>().value();
|
||||
result = _(list).takeWhile<TResult>(predicateFn).value();
|
||||
result = _(list).takeWhile<TResult>(predicateFn, any).value();
|
||||
result = _(list).takeWhile<TResult>('').value();
|
||||
result = _(list).takeWhile<TResult>('', any).value();
|
||||
result = _(list).takeWhile<{a: number;}, TResult>({a: 42}).value();
|
||||
}
|
||||
|
||||
result = <number[]>_.union([1, 2, 3], [101, 2, 1, 10], [2, 1]);
|
||||
|
||||
result = <number[]>_([1, 2, 3]).union([101, 2, 1, 10], [2, 1]).value();
|
||||
|
||||
154
lodash/lodash.d.ts
vendored
154
lodash/lodash.d.ts
vendored
@@ -671,66 +671,6 @@ declare module _ {
|
||||
first<TResult>(): TResult;
|
||||
}
|
||||
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
* Takes the first items from an array or list based on a predicate
|
||||
* @param array The array or list of items on which the result set will be based
|
||||
* @param predicate A predicate function to determine whether a value will be taken. Optional; defaults to identity.
|
||||
* @param [thisArg] The this binding of predicate.
|
||||
*/
|
||||
takeWhile<T>(
|
||||
array: (Array<T>|List<T>),
|
||||
predicate?: ListIterator<T, boolean>,
|
||||
thisArg?: any
|
||||
): T[];
|
||||
|
||||
/**
|
||||
* Takes the first items from an array or list based on a predicate
|
||||
* @param array The array or list of items on which the result set will be based
|
||||
* @param pluckValue Uses a _.property style callback to return the property value of the given element
|
||||
*/
|
||||
takeWhile<T>(
|
||||
array: (Array<T>|List<T>),
|
||||
pluckValue: string
|
||||
): any[];
|
||||
|
||||
/**
|
||||
* Takes the first items from an array or list based on a predicate
|
||||
* @param array The array or list of items on which the result set will be based
|
||||
* @param whereValue Uses a _.matches style callback to return the first elements that match the given value
|
||||
*/
|
||||
takeWhile<W, T>(
|
||||
array: (Array<T>|List<T>),
|
||||
whereValue: W
|
||||
): T[];
|
||||
}
|
||||
|
||||
interface LoDashArrayWrapper<T> {
|
||||
/**
|
||||
* Takes the first items based on a predicate
|
||||
* @param predicate The function called per element.
|
||||
* @param [thisArg] The this binding of callback.
|
||||
**/
|
||||
takeWhile(
|
||||
predicate: ListIterator<T, boolean>,
|
||||
thisArg?: any): LoDashArrayWrapper<T>;
|
||||
|
||||
/**
|
||||
* Takes the first items based on a predicate
|
||||
* @param pluckValue Uses a _.property style callback to return the property value of the given element
|
||||
**/
|
||||
takeWhile<T>(
|
||||
pluckValue: string): LoDashArrayWrapper<any>;
|
||||
|
||||
/**
|
||||
* Takes the first items based on a predicate
|
||||
* @param whereValue Uses a _.matches style callback to return the first elements that match the given value
|
||||
**/
|
||||
takeWhile<W, T>(
|
||||
whereValue: W): LoDashArrayWrapper<T>;
|
||||
|
||||
}
|
||||
|
||||
interface MaybeNestedList<T> extends List<T|List<T>> { }
|
||||
interface RecursiveList<T> extends List<T|RecursiveList<T>> { }
|
||||
|
||||
@@ -1531,6 +1471,100 @@ declare module _ {
|
||||
): LoDashArrayWrapper<TValue>;
|
||||
}
|
||||
|
||||
//_.takeWhile
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
* Creates a slice of array with elements taken from the beginning. Elements are taken until predicate returns
|
||||
* falsey. The predicate is bound to thisArg and invoked with three arguments: (value, index, array).
|
||||
*
|
||||
* If a property name is provided for predicate 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 predicate the created _.matches style callback returns true for elements that
|
||||
* have the properties of the given object, else false.
|
||||
*
|
||||
* @param array The array to query.
|
||||
* @param predicate The function invoked per iteration.
|
||||
* @param thisArg The this binding of predicate.
|
||||
* @return Returns the slice of array.
|
||||
*/
|
||||
takeWhile<TValue>(
|
||||
array: List<TValue>,
|
||||
predicate?: ListIterator<TValue, boolean>,
|
||||
thisArg?: any
|
||||
): TValue[];
|
||||
|
||||
/**
|
||||
* @see _.takeWhile
|
||||
*/
|
||||
takeWhile<TValue>(
|
||||
array: List<TValue>,
|
||||
predicate?: string,
|
||||
thisArg?: any
|
||||
): TValue[];
|
||||
|
||||
/**
|
||||
* @see _.takeWhile
|
||||
*/
|
||||
takeWhile<TWhere, TValue>(
|
||||
array: List<TValue>,
|
||||
predicate?: TWhere
|
||||
): TValue[];
|
||||
}
|
||||
|
||||
interface LoDashArrayWrapper<T> {
|
||||
/**
|
||||
* @see _.takeWhile
|
||||
*/
|
||||
takeWhile(
|
||||
predicate?: ListIterator<T, boolean>,
|
||||
thisArg?: any
|
||||
): LoDashArrayWrapper<T>;
|
||||
|
||||
/**
|
||||
* @see _.takeWhile
|
||||
*/
|
||||
takeWhile(
|
||||
predicate?: string,
|
||||
thisArg?: any
|
||||
): LoDashArrayWrapper<T>;
|
||||
|
||||
/**
|
||||
* @see _.takeWhile
|
||||
*/
|
||||
takeWhile<TWhere>(
|
||||
predicate?: TWhere
|
||||
): LoDashArrayWrapper<T>;
|
||||
}
|
||||
|
||||
interface LoDashObjectWrapper<T> {
|
||||
/**
|
||||
* @see _.takeWhile
|
||||
*/
|
||||
takeWhile<TValue>(
|
||||
predicate?: ListIterator<TValue, boolean>,
|
||||
thisArg?: any
|
||||
): LoDashArrayWrapper<TValue>;
|
||||
|
||||
/**
|
||||
* @see _.takeWhile
|
||||
*/
|
||||
takeWhile<TValue>(
|
||||
predicate?: string,
|
||||
thisArg?: any
|
||||
): LoDashArrayWrapper<TValue>;
|
||||
|
||||
/**
|
||||
* @see _.takeWhile
|
||||
*/
|
||||
takeWhile<TWhere, TValue>(
|
||||
predicate?: TWhere
|
||||
): LoDashArrayWrapper<TValue>;
|
||||
}
|
||||
|
||||
//_.union
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user