diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index c56d79817..e7e827300 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -261,12 +261,41 @@ result = <_.List>_.fill(testFillList, 'a', 0, 3); result = _(testFillArray).fill(0, 0, 3).value(); result = <_.List>_(testFillList).fill(0, 0, 3).value(); +// _.findIndex +module TestFindIndex { + let array: TResult[]; + let list: _.List; + let predicateFn: (value: TResult, index?: number, collection?: _.List) => boolean; + let result: number; -result = _.findIndex(['apple', 'banana', 'beet'], function (f) { - return /^b/.test(f); -}); -result = _.findIndex(['apple', 'banana', 'beet'], 'apple'); -result = _.findIndex([{ food: 'apple' }, { food: 'banana' }, { food: 'beet' }], { food: 'apple' }); + result = _.findIndex(array); + result = _.findIndex(array, predicateFn); + result = _.findIndex(array, predicateFn, any); + result = _.findIndex(array, ''); + result = _.findIndex(array, '', any); + result = _.findIndex<{a: number}, TResult>(array, {a: 42}); + + result = _.findIndex(list); + result = _.findIndex(list, predicateFn); + result = _.findIndex(list, predicateFn, any); + result = _.findIndex(list, ''); + result = _.findIndex(list, '', any); + result = _.findIndex<{a: number}, TResult>(list, {a: 42}); + + result = _(array).findIndex(); + result = _(array).findIndex(predicateFn); + result = _(array).findIndex(predicateFn, any); + result = _(array).findIndex(''); + result = _(array).findIndex('', any); + result = _(array).findIndex<{a: number}>({a: 42}); + + result = _(list).findIndex(); + result = _(list).findIndex(predicateFn); + result = _(list).findIndex(predicateFn, any); + result = _(list).findIndex(''); + result = _(list).findIndex('', any); + result = _(list).findIndex<{a: number}>({a: 42}); +} result = _.findLastIndex(['apple', 'banana', 'beet'], function (f: string) { return /^b/.test(f); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 5d8afa549..10171fd57 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -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( - array: Array, - callback: ListIterator, - 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( array: List, - callback: ListIterator, - thisArg?: any): number; + predicate?: ListIterator, + thisArg?: any + ): number; /** - * @see _.findIndex - **/ - findIndex( - array: Array, - pluckValue: string): number; - - /** - * @see _.findIndex - **/ + * @see _.findIndex + */ findIndex( array: List, - pluckValue: string): number; + predicate?: string, + thisArg?: any + ): number; /** - * @see _.findIndex - **/ - findIndex( - array: Array, - whereDictionary: W): number; - - /** - * @see _.findIndex - **/ + * @see _.findIndex + */ findIndex( array: List, - whereDictionary: W): number; + predicate?: W + ): number; + } + + interface LoDashArrayWrapper { + /** + * @see _.findIndex + */ + findIndex( + predicate?: ListIterator, + thisArg?: any + ): number; + + /** + * @see _.findIndex + */ + findIndex( + predicate?: string, + thisArg?: any + ): number; + + /** + * @see _.findIndex + */ + findIndex( + predicate?: W + ): number; + } + + interface LoDashObjectWrapper { + /** + * @see _.findIndex + */ + findIndex( + predicate?: ListIterator, + thisArg?: any + ): number; + + /** + * @see _.findIndex + */ + findIndex( + predicate?: string, + thisArg?: any + ): number; + + /** + * @see _.findIndex + */ + findIndex( + predicate?: W + ): number; } //_.findLastIndex