From f3840dd3df0da771a82f174958bc376e6ef02d99 Mon Sep 17 00:00:00 2001 From: Erik Krogh Kristensen Date: Mon, 6 Mar 2017 10:54:34 +0100 Subject: [PATCH] Underscore: A bunch of fixes, and added a lot of "or undefined" for strict nulls. --- underscore/index.d.ts | 115 +++++++++++++++++---------------- underscore/underscore-tests.ts | 2 +- 2 files changed, 61 insertions(+), 56 deletions(-) diff --git a/underscore/index.d.ts b/underscore/index.d.ts index 48452b9e2e..f0f6784de3 100644 --- a/underscore/index.d.ts +++ b/underscore/index.d.ts @@ -153,9 +153,19 @@ declare module _ { **/ map( list: _.List, - iterator: _.ListIterator | _.IterateePropertyShorthand | _.IterateeMatcherShorthand, + iterator: _.ListIterator, context?: any): TResult[]; + map( + list: _.List, + iterator: _.IterateePropertyShorthand, + context?: any): T[]; + + map( + list: _.List, + iterator: _.IterateeMatcherShorthand, + context?: any): boolean[]; + /** * @see _.map * @param object Maps the properties of this object. @@ -171,18 +181,7 @@ declare module _ { /** * @see _.map **/ - collect( - list: _.List, - iterator: _.ListIterator | _.IterateePropertyShorthand | _.IterateeMatcherShorthand, - context?: any): TResult[]; - - /** - * @see _.map - **/ - collect( - object: _.Dictionary, - iterator: _.ObjectIterator, - context?: any): TResult[]; + collect: typeof _.map; /** * Also known as inject and foldl, reduce boils down a list of values into a single value. @@ -196,7 +195,7 @@ declare module _ { * @return Reduced object result. **/ reduce( - list: _.Collection, + list: _.List, iterator: _.MemoIterator, memo?: TResult, context?: any): TResult; @@ -211,11 +210,17 @@ declare module _ { * @see _.reduce **/ inject( - list: _.Collection, + list: _.List, iterator: _.MemoIterator, memo?: TResult, context?: any): TResult; + inject( + list: _.Dictionary, + iterator: _.MemoObjectIterator, + memo?: TResult, + context?: any): TResult; + /** * @see _.reduce **/ @@ -262,7 +267,7 @@ declare module _ { find( list: _.List, iterator: _.ListIterator, - context?: any): T; + context?: any): T | undefined; /** * @see _.find @@ -270,21 +275,21 @@ declare module _ { find( object: _.Dictionary, iterator: _.ObjectIterator, - context?: any): T; + context?: any): T | undefined; /** * @see _.find **/ find( object: _.List | _.Dictionary, - iterator: U): T; + iterator: U): T | undefined; /** * @see _.find **/ find( object: _.List | _.Dictionary, - iterator: string): T; + iterator: string): T | undefined; /** * @see _.find @@ -292,7 +297,7 @@ declare module _ { detect( list: _.List, iterator: _.ListIterator, - context?: any): T; + context?: any): T | undefined; /** * @see _.find @@ -300,21 +305,21 @@ declare module _ { detect( object: _.Dictionary, iterator: _.ObjectIterator, - context?: any): T; + context?: any): T | undefined; /** * @see _.find **/ detect( object: _.List | _.Dictionary, - iterator: U): T; + iterator: U): T | undefined; /** * @see _.find **/ detect( object: _.List | _.Dictionary, - iterator: string): T; + iterator: string): T | undefined; /** * Looks through each value in the list, returning an array of all the values that pass a truth @@ -372,7 +377,7 @@ declare module _ { **/ findWhere( list: _.List, - properties: U): T; + properties: U): T | undefined; /** * Returns the values in list without the elements that the truth test (iterator) passes. @@ -754,7 +759,7 @@ declare module _ { * @param array Retrieves the first element of this array. * @return Returns the first element of `array`. **/ - first(array: _.List): T; + first(array: _.List): T | undefined; /** * @see _.first @@ -767,7 +772,7 @@ declare module _ { /** * @see _.first **/ - head(array: _.List): T; + head(array: _.List): T | undefined; /** * @see _.first @@ -804,7 +809,7 @@ declare module _ { * @param array Retrieves the last element of this array. * @return Returns the last element of `array`. **/ - last(array: _.List): T; + last(array: _.List): T | undefined; /** * @see _.last @@ -3768,7 +3773,7 @@ declare module _ { * @param attrs Object with key values pair * @return Predicate function **/ - matches(attrs: T): _.ListIterator; + matches(attrs: T): _.ListIterator; /** * Returns a predicate function that will tell you if a passed in object contains all of the key/value properties present in attrs. @@ -3776,7 +3781,7 @@ declare module _ { * @param attrs Object with key values pair * @return Predicate function **/ - matcher(attrs: T): _.ListIterator; + matcher(attrs: T): _.ListIterator; /** * Returns a function that will itself return the key property of any passed-in object. @@ -4100,22 +4105,22 @@ declare module _ { * Wrapped type `any[]`. * @see _.each **/ - each(iterator: _.ListIterator, context?: any): T[]; + each(iterator: _.ListIterator, context?: any): _.List; /** * @see _.each **/ - each(iterator: _.ObjectIterator, context?: any): T[]; + each(iterator: _.ObjectIterator, context?: any): _.List; /** * @see _.each **/ - forEach(iterator: _.ListIterator, context?: any): T[]; + forEach(iterator: _.ListIterator, context?: any): _.List; /** * @see _.each **/ - forEach(iterator: _.ObjectIterator, context?: any): T[]; + forEach(iterator: _.ObjectIterator, context?: any): _.List; /** * Wrapped type `any[]`. @@ -4170,32 +4175,32 @@ declare module _ { * Wrapped type `any[]`. * @see _.find **/ - find(iterator: _.ListIterator | _.ObjectIterator, context?: any): T; + find(iterator: _.ListIterator | _.ObjectIterator, context?: any): T | undefined; /** * @see _.find **/ - find(interator: U): T; + find(interator: U): T | undefined; /** * @see _.find **/ - find(interator: string): T; + find(interator: string): T | undefined; /** * @see _.find **/ - detect(iterator: _.ListIterator | _.ObjectIterator, context?: any): T; + detect(iterator: _.ListIterator | _.ObjectIterator, context?: any): T | undefined; /** * @see _.find **/ - detect(interator?: U): T; + detect(interator?: U): T | undefined; /** * @see _.find **/ - detect(interator?: string): T; + detect(interator?: string): T | undefined; /** * Wrapped type `any[]`. @@ -4218,7 +4223,7 @@ declare module _ { * Wrapped type `any[]`. * @see _.findWhere **/ - findWhere(properties: U): T; + findWhere(properties: U): T | undefined; /** * Wrapped type `any[]`. @@ -4399,7 +4404,7 @@ declare module _ { * Wrapped type `any[]`. * @see _.first **/ - first(): T; + first(): T | undefined; /** * Wrapped type `any[]`. @@ -4410,7 +4415,7 @@ declare module _ { /** * @see _.first **/ - head(): T; + head(): T | undefined; /** * @see _.first @@ -4437,7 +4442,7 @@ declare module _ { * Wrapped type `any[]`. * @see _.last **/ - last(): T; + last(): T | undefined; /** * Wrapped type `any[]`. @@ -4690,7 +4695,7 @@ declare module _ { * Wrapped type `Function`. * @see _.negate **/ - negate(): boolean; + negate(): (...args: any[]) => boolean; /** * Wrapped type `Function[]`. @@ -4805,13 +4810,13 @@ declare module _ { * Wrapped type `any[]`. * @see _.matches **/ - matches(): _.ListIterator; + matches(): _.ListIterator; /** * Wrapped type `any[]`. * @see _.matcher **/ - matcher(): _.ListIterator; + matcher(): _.ListIterator; /** * Wrapped type `string`. @@ -5130,32 +5135,32 @@ declare module _ { * Wrapped type `any[]`. * @see _.find **/ - find(iterator: _.ListIterator | _.ObjectIterator, context?: any): _ChainSingle; + find(iterator: _.ListIterator | _.ObjectIterator, context?: any): _ChainSingle; /** * @see _.find **/ - find(interator: U): _ChainSingle; + find(interator: U): _ChainSingle; /** * @see _.find **/ - find(interator: string): _ChainSingle; + find(interator: string): _ChainSingle; /** * @see _.find **/ - detect(iterator: _.ListIterator | _.ObjectIterator, context?: any): _ChainSingle; + detect(iterator: _.ListIterator | _.ObjectIterator, context?: any): _ChainSingle; /** * @see _.find **/ - detect(interator: U): _ChainSingle; + detect(interator: U): _ChainSingle; /** * @see _.find **/ - detect(interator: string): _ChainSingle; + detect(interator: string): _ChainSingle; /** * Wrapped type `any[]`. @@ -5359,7 +5364,7 @@ declare module _ { * Wrapped type `any[]`. * @see _.first **/ - first(): _ChainSingle; + first(): _ChainSingle; /** * Wrapped type `any[]`. @@ -5765,13 +5770,13 @@ declare module _ { * Wrapped type `any[]`. * @see _.matches **/ - matches(): _Chain; + matches(): _Chain; /** * Wrapped type `any[]`. * @see _.matcher **/ - matcher(): _Chain; + matcher(): _Chain; /** * Wrapped type `string`. diff --git a/underscore/underscore-tests.ts b/underscore/underscore-tests.ts index d3a5729022..f5e8e984ef 100644 --- a/underscore/underscore-tests.ts +++ b/underscore/underscore-tests.ts @@ -212,7 +212,7 @@ interface Family { name: string; relation: string; } -var isUncleMoe = _.matches({ name: 'moe', relation: 'uncle' }); +var isUncleMoe = _.matches({ name: 'moe', relation: 'uncle' }); _.filter([{ name: 'larry', relation: 'father' }, { name: 'moe', relation: 'uncle' }], isUncleMoe);