diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index d8be1f68a..b1e2853d8 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -1793,9 +1793,31 @@ var TestDefaultsDeepSource = {'user': {'name': 'fred', 'age': 36}}; result = _.defaultsDeep(TestDefaultsDeepObject, TestDefaultsDeepSource); result = _(TestDefaultsDeepObject).defaultsDeep(TestDefaultsDeepSource).value(); -result = _.findKey({ 'a': 1, 'b': 2, 'c': 3, 'd': 4 }, function (num) { - return num % 2 == 0; -}); +// _.findKey +module TestFindKey { + let predicateFn: (value: any, key?: string, object?: {}) => boolean; + let result: string; + + result = _.findKey<{a: string;}>({a: ''}); + + result = _.findKey<{a: string;}>({a: ''}, predicateFn); + result = _.findKey<{a: string;}>({a: ''}, predicateFn, any); + + result = _.findKey<{a: string;}>({a: ''}, ''); + result = _.findKey<{a: string;}>({a: ''}, '', any); + + result = _.findKey<{a: number;}, {a: string;}>({a: ''}, {a: 42}); + + result = _<{a: string;}>({a: ''}).findKey(); + + result = _<{a: string;}>({a: ''}).findKey(predicateFn); + result = _<{a: string;}>({a: ''}).findKey(predicateFn, any); + + result = _<{a: string;}>({a: ''}).findKey(''); + result = _<{a: string;}>({a: ''}).findKey('', any); + + result = _<{a: string;}>({a: ''}).findKey<{a: number;}>({a: 42}); +} result = _.findLastKey({ 'a': 1, 'b': 2, 'c': 3, 'd': 4 }, function (num) { return num % 2 == 1; diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 1d500be9c..f23053d9b 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -6925,33 +6925,70 @@ declare module _ { //_.findKey interface LoDashStatic { /** - * This method is like _.findIndex except that it returns the key of the first element that - * passes the callback check, instead of the element itself. - * @param object The object to search. - * @param callback The function called per iteration. - * @param thisArg The this binding of callback. - * @return The key of the found element, else undefined. - **/ - findKey( - object: any, - callback: (value: any) => boolean, - thisArg?: any): string; + * This method is like _.find except that it returns the key 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 object The object to search. + * @param predicate The function invoked per iteration. + * @param thisArg The this binding of predicate. + * @return Returns the key of the matched element, else undefined. + */ + findKey( + object: TObject, + predicate?: ObjectIterator, + thisArg?: any + ): string; /** - * @see _.findKey - * @param pluckValue _.pluck style callback - **/ - findKey( - object: any, - pluckValue: string): string; + * @see _.findKey + */ + findKey( + object: TObject, + predicate?: string, + thisArg?: any + ): string; /** - * @see _.findKey - * @param whereValue _.where style callback - **/ - findKey, T>( - object: T, - whereValue: W): string; + * @see _.findKey + */ + findKey, TObject>( + object: TObject, + predicate?: TWhere + ): string; + } + + interface LoDashObjectWrapper { + /** + * @see _.findKey + */ + findKey( + predicate?: ObjectIterator, + thisArg?: any + ): string; + + /** + * @see _.findKey + */ + findKey( + predicate?: string, + thisArg?: any + ): string; + + /** + * @see _.findKey + */ + findKey>( + predicate?: TWhere + ): string; } //_.findLastKey @@ -8793,7 +8830,7 @@ declare module _ { } interface ObjectIterator { - (element: T, key: string, collection: any): TResult; + (element: T, key?: string, collection?: any): TResult; } interface MemoVoidIterator {