mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-08-25 11:11:46 +08:00
Merge pull request #6077 from chrootsu/lodash-findIndex
lodash: changed _.findIndex() method
This commit is contained in:
+34
-5
@@ -261,12 +261,41 @@ result = <_.List<string>>_.fill<string>(testFillList, 'a', 0, 3);
|
||||
result = <number[]>_(testFillArray).fill<number>(0, 0, 3).value();
|
||||
result = <_.List<number>>_(testFillList).fill<number>(0, 0, 3).value();
|
||||
|
||||
// _.findIndex
|
||||
module TestFindIndex {
|
||||
let array: TResult[];
|
||||
let list: _.List<TResult>;
|
||||
let predicateFn: (value: TResult, index?: number, collection?: _.List<TResult>) => boolean;
|
||||
let result: number;
|
||||
|
||||
result = <number>_.findIndex(['apple', 'banana', 'beet'], function (f) {
|
||||
return /^b/.test(f);
|
||||
});
|
||||
result = <number>_.findIndex(['apple', 'banana', 'beet'], 'apple');
|
||||
result = <number>_.findIndex([{ food: 'apple' }, { food: 'banana' }, { food: 'beet' }], { food: 'apple' });
|
||||
result = _.findIndex<TResult>(array);
|
||||
result = _.findIndex<TResult>(array, predicateFn);
|
||||
result = _.findIndex<TResult>(array, predicateFn, any);
|
||||
result = _.findIndex<TResult>(array, '');
|
||||
result = _.findIndex<TResult>(array, '', any);
|
||||
result = _.findIndex<{a: number}, TResult>(array, {a: 42});
|
||||
|
||||
result = _.findIndex<TResult>(list);
|
||||
result = _.findIndex<TResult>(list, predicateFn);
|
||||
result = _.findIndex<TResult>(list, predicateFn, any);
|
||||
result = _.findIndex<TResult>(list, '');
|
||||
result = _.findIndex<TResult>(list, '', any);
|
||||
result = _.findIndex<{a: number}, TResult>(list, {a: 42});
|
||||
|
||||
result = _<TResult>(array).findIndex();
|
||||
result = _<TResult>(array).findIndex(predicateFn);
|
||||
result = _<TResult>(array).findIndex(predicateFn, any);
|
||||
result = _<TResult>(array).findIndex('');
|
||||
result = _<TResult>(array).findIndex('', any);
|
||||
result = _<TResult>(array).findIndex<{a: number}>({a: 42});
|
||||
|
||||
result = _(list).findIndex();
|
||||
result = _(list).findIndex<TResult>(predicateFn);
|
||||
result = _(list).findIndex<TResult>(predicateFn, any);
|
||||
result = _(list).findIndex('');
|
||||
result = _(list).findIndex('', any);
|
||||
result = _(list).findIndex<{a: number}>({a: 42});
|
||||
}
|
||||
|
||||
result = <number>_.findLastIndex(['apple', 'banana', 'beet'], function (f: string) {
|
||||
return /^b/.test(f);
|
||||
|
||||
Vendored
+79
-38
@@ -460,54 +460,95 @@ declare module _ {
|
||||
//_.findIndex
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
* This method is like _.find except that it returns the index of the first element that passes
|
||||
* the callback check, instead of the element itself.
|
||||
* @param array The array to search.
|
||||
* @param {(Function|Object|string)} callback The function called per iteration. If a property name or object is provided it will be
|
||||
* used to create a ".pluck" or ".where" style callback, respectively.
|
||||
* @param thisArg The this binding of callback.
|
||||
* @return Returns the index of the found element, else -1.
|
||||
**/
|
||||
findIndex<T>(
|
||||
array: Array<T>,
|
||||
callback: ListIterator<T, boolean>,
|
||||
thisArg?: any): number;
|
||||
|
||||
/**
|
||||
* @see _.findIndex
|
||||
**/
|
||||
* This method is like _.find except that it returns the index of the first element predicate returns truthy
|
||||
* for instead of the element itself.
|
||||
*
|
||||
* 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 search.
|
||||
* @param predicate The function invoked per iteration.
|
||||
* @param thisArg The this binding of predicate.
|
||||
* @return Returns the index of the found element, else -1.
|
||||
*/
|
||||
findIndex<T>(
|
||||
array: List<T>,
|
||||
callback: ListIterator<T, boolean>,
|
||||
thisArg?: any): number;
|
||||
predicate?: ListIterator<T, boolean>,
|
||||
thisArg?: any
|
||||
): number;
|
||||
|
||||
/**
|
||||
* @see _.findIndex
|
||||
**/
|
||||
findIndex<T>(
|
||||
array: Array<T>,
|
||||
pluckValue: string): number;
|
||||
|
||||
/**
|
||||
* @see _.findIndex
|
||||
**/
|
||||
* @see _.findIndex
|
||||
*/
|
||||
findIndex<T>(
|
||||
array: List<T>,
|
||||
pluckValue: string): number;
|
||||
predicate?: string,
|
||||
thisArg?: any
|
||||
): number;
|
||||
|
||||
/**
|
||||
* @see _.findIndex
|
||||
**/
|
||||
findIndex<W, T>(
|
||||
array: Array<T>,
|
||||
whereDictionary: W): number;
|
||||
|
||||
/**
|
||||
* @see _.findIndex
|
||||
**/
|
||||
* @see _.findIndex
|
||||
*/
|
||||
findIndex<W, T>(
|
||||
array: List<T>,
|
||||
whereDictionary: W): number;
|
||||
predicate?: W
|
||||
): number;
|
||||
}
|
||||
|
||||
interface LoDashArrayWrapper<T> {
|
||||
/**
|
||||
* @see _.findIndex
|
||||
*/
|
||||
findIndex(
|
||||
predicate?: ListIterator<T, boolean>,
|
||||
thisArg?: any
|
||||
): number;
|
||||
|
||||
/**
|
||||
* @see _.findIndex
|
||||
*/
|
||||
findIndex(
|
||||
predicate?: string,
|
||||
thisArg?: any
|
||||
): number;
|
||||
|
||||
/**
|
||||
* @see _.findIndex
|
||||
*/
|
||||
findIndex<W>(
|
||||
predicate?: W
|
||||
): number;
|
||||
}
|
||||
|
||||
interface LoDashObjectWrapper<T> {
|
||||
/**
|
||||
* @see _.findIndex
|
||||
*/
|
||||
findIndex<TResult>(
|
||||
predicate?: ListIterator<TResult, boolean>,
|
||||
thisArg?: any
|
||||
): number;
|
||||
|
||||
/**
|
||||
* @see _.findIndex
|
||||
*/
|
||||
findIndex(
|
||||
predicate?: string,
|
||||
thisArg?: any
|
||||
): number;
|
||||
|
||||
/**
|
||||
* @see _.findIndex
|
||||
*/
|
||||
findIndex<W>(
|
||||
predicate?: W
|
||||
): number;
|
||||
}
|
||||
|
||||
//_.findLastIndex
|
||||
|
||||
Reference in New Issue
Block a user