diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index d0cfba393..974d0b966 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -2739,9 +2739,46 @@ module TestFindKey { } } -result = _.findLastKey({ 'a': 1, 'b': 2, 'c': 3, 'd': 4 }, function (num) { - return num % 2 == 1; -}); +// _.findLastKey +module TestFindLastKey { + let result: string; + + { + let predicateFn: (value: any, key?: string, object?: {}) => boolean; + + result = _.findLastKey<{a: string;}>({a: ''}); + + result = _.findLastKey<{a: string;}>({a: ''}, predicateFn); + result = _.findLastKey<{a: string;}>({a: ''}, predicateFn, any); + + + result = _.findLastKey<{a: string;}>({a: ''}, ''); + result = _.findLastKey<{a: string;}>({a: ''}, '', any); + + result = _.findLastKey<{a: number;}, {a: string;}>({a: ''}, {a: 42}); + + result = _<{a: string;}>({a: ''}).findLastKey(); + + result = _<{a: string;}>({a: ''}).findLastKey(predicateFn); + result = _<{a: string;}>({a: ''}).findLastKey(predicateFn, any); + + + result = _<{a: string;}>({a: ''}).findLastKey(''); + result = _<{a: string;}>({a: ''}).findLastKey('', any); + + result = _<{a: string;}>({a: ''}).findLastKey<{a: number;}>({a: 42}); + } + + { + let predicateFn: (value: string, key?: string, collection?: _.Dictionary) => boolean; + + result = _.findLastKey({a: ''}, predicateFn); + result = _.findLastKey({a: ''}, predicateFn, any); + + result = _<{a: string;}>({a: ''}).findLastKey(predicateFn); + result = _<{a: string;}>({a: ''}).findLastKey(predicateFn, any); + } +} result = _.forIn(new Dog('Dagny'), function (value, key) { console.log(key); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index e327e87e8..c07cfd0e3 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -7830,32 +7830,86 @@ declare module _ { //_.findLastKey interface LoDashStatic { /** - * This method is like _.findKey except that it iterates over elements of a collection in the opposite order. - * @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. - **/ - findLastKey( - object: any, - callback: (value: any) => boolean, - thisArg?: any): string; + * This method is like _.findKey except that it iterates over elements of a collection in the opposite order. + * + * 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. + */ + findLastKey( + object: TObject, + predicate?: DictionaryIterator, + thisArg?: any + ): string; /** - * @see _.findLastKey - * @param pluckValue _.pluck style callback - **/ - findLastKey( - object: any, - pluckValue: string): string; + * @see _.findLastKey + */ + findLastKey( + object: TObject, + predicate?: ObjectIterator, + thisArg?: any + ): string; /** - * @see _.findLastKey - * @param whereValue _.where style callback - **/ - findLastKey, T>( - object: T, - whereValue: W): string; + * @see _.findLastKey + */ + findLastKey( + object: TObject, + predicate?: string, + thisArg?: any + ): string; + + /** + * @see _.findLastKey + */ + findLastKey, TObject>( + object: TObject, + predicate?: TWhere + ): string; + } + + interface LoDashObjectWrapper { + /** + * @see _.findLastKey + */ + findLastKey( + predicate?: DictionaryIterator, + thisArg?: any + ): string; + + /** + * @see _.findLastKey + */ + findLastKey( + predicate?: ObjectIterator, + thisArg?: any + ): string; + + /** + * @see _.findLastKey + */ + findLastKey( + predicate?: string, + thisArg?: any + ): string; + + /** + * @see _.findLastKey + */ + findLastKey>( + predicate?: TWhere + ): string; } //_.forIn