Fix wrongly-defined return type for _.matches, _.matcher

This commit is contained in:
Michael Heasell
2019-02-15 11:31:52 +00:00
parent f9619dd065
commit f82f720bb3
2 changed files with 8 additions and 2 deletions

View File

@@ -69,6 +69,10 @@ declare module _ {
[index: string]: T;
}
interface Predicate<T> {
(value: T): boolean;
}
interface ListIterator<T, TResult> {
(value: T, index: number, list: List<T>): TResult;
}
@@ -3782,7 +3786,7 @@ declare module _ {
* @param attrs Object with key values pair
* @return Predicate function
**/
matches<T>(attrs: T): _.ListIterator<T, boolean>;
matches<T>(attrs: T): _.Predicate<T>;
/**
* Returns a predicate function that will tell you if a passed in object contains all of the key/value properties present in attrs.
@@ -3790,7 +3794,7 @@ declare module _ {
* @param attrs Object with key values pair
* @return Predicate function
**/
matcher<T>(attrs: T): _.ListIterator<T, boolean>;
matcher<T>(attrs: T): _.Predicate<T>;
/**
* Returns a function that will itself return the key property of any passed-in object.

View File

@@ -216,6 +216,8 @@ interface Family {
}
var isUncleMoe = _.matches<Family>({ name: 'moe', relation: 'uncle' });
_.filter([{ name: 'larry', relation: 'father' }, { name: 'moe', relation: 'uncle' }], isUncleMoe);
var uncleMoe: Family = { name: 'moe', relation: 'uncle' };
isUncleMoe(uncleMoe);