lodash: improved signatures of the method _.findKey

This commit is contained in:
Ilya Mochalov
2015-10-05 23:07:07 +05:00
parent 06e62de975
commit ba1ababebb
2 changed files with 46 additions and 14 deletions
+28 -13
View File
@@ -2013,28 +2013,43 @@ result = <DefaultsDeepResult>_(TestDefaultsDeepObject).defaultsDeep<DefaultsDeep
// _.findKey
module TestFindKey {
let predicateFn: (value: any, key?: string, object?: {}) => boolean;
let result: string;
result = _.findKey<{a: string;}>({a: ''});
{
let predicateFn: (value: any, key?: string, object?: {}) => boolean;
result = _.findKey<{a: string;}>({a: ''}, predicateFn);
result = _.findKey<{a: string;}>({a: ''}, predicateFn, any);
result = _.findKey<{a: string;}>({a: ''});
result = _.findKey<{a: string;}>({a: ''}, '');
result = _.findKey<{a: string;}>({a: ''}, '', any);
result = _.findKey<{a: string;}>({a: ''}, predicateFn);
result = _.findKey<{a: string;}>({a: ''}, predicateFn, any);
result = _.findKey<{a: number;}, {a: string;}>({a: ''}, {a: 42});
result = _<{a: string;}>({a: ''}).findKey();
result = _.findKey<{a: string;}>({a: ''}, '');
result = _.findKey<{a: string;}>({a: ''}, '', any);
result = _<{a: string;}>({a: ''}).findKey(predicateFn);
result = _<{a: string;}>({a: ''}).findKey(predicateFn, any);
result = _.findKey<{a: number;}, {a: string;}>({a: ''}, {a: 42});
result = _<{a: string;}>({a: ''}).findKey('');
result = _<{a: string;}>({a: ''}).findKey('', any);
result = _<{a: string;}>({a: ''}).findKey();
result = _<{a: string;}>({a: ''}).findKey<{a: number;}>({a: 42});
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});
}
{
let predicateFn: (value: string, key?: string, collection?: _.Dictionary<string>) => boolean;
result = _.findKey<string, {a: string;}>({a: ''}, predicateFn);
result = _.findKey<string, {a: string;}>({a: ''}, predicateFn, any);
result = _<{a: string;}>({a: ''}).findKey<string>(predicateFn);
result = _<{a: string;}>({a: ''}).findKey<string>(predicateFn, any);
}
}
result = <string>_.findLastKey({ 'a': 1, 'b': 2, 'c': 3, 'd': 4 }, function (num) {
+18 -1
View File
@@ -7104,6 +7104,15 @@ declare module _ {
* @param thisArg The this binding of predicate.
* @return Returns the key of the matched element, else undefined.
*/
findKey<TValues, TObject>(
object: TObject,
predicate?: DictionaryIterator<TValues, boolean>,
thisArg?: any
): string;
/**
* @see _.findKey
*/
findKey<TObject>(
object: TObject,
predicate?: ObjectIterator<any, boolean>,
@@ -7129,6 +7138,14 @@ declare module _ {
}
interface LoDashObjectWrapper<T> {
/**
* @see _.findKey
*/
findKey<TValues>(
predicate?: DictionaryIterator<TValues, boolean>,
thisArg?: any
): string;
/**
* @see _.findKey
*/
@@ -8988,7 +9005,7 @@ declare module _ {
}
interface DictionaryIterator<T, TResult> {
(value: T, key: string, collection: Dictionary<T>): TResult;
(value: T, key?: string, collection?: Dictionary<T>): TResult;
}
interface ObjectIterator<T, TResult> {