diff --git a/underscore/underscore-tests.ts b/underscore/underscore-tests.ts index 0fb7ac004e..11624abeb1 100644 --- a/underscore/underscore-tests.ts +++ b/underscore/underscore-tests.ts @@ -69,18 +69,18 @@ _.countBy([1, 2, 3, 4, 5], (num) => (num % 2 == 0) ? 'even' : 'odd'); _.shuffle([1, 2, 3, 4, 5, 6]); -(function(a, b, c, d){ return _.toArray(arguments).slice(1); })(1, 2, 3, 4); +(function (a, b, c, d) { return _.toArray(arguments).slice(1); })(1, 2, 3, 4); _.size({ one: 1, two: 2, three: 3 }); -_.partition([0, 1, 2, 3, 4, 5], (num)=>{return num % 2 ==0}); +_.partition([0, 1, 2, 3, 4, 5], (num) => {return num % 2 == 0 }); interface Family { name: string; - relation : string; + relation: string; } -var isUncleMoe = _.matches({name : 'moe', relation : 'uncle'}); -_.filter([{name: 'larry', relation : 'father'}, {name : 'moe', relation : 'uncle'}], isUncleMoe); +var isUncleMoe = _.matches({ name: 'moe', relation: 'uncle' }); +_.filter([{ name: 'larry', relation: 'father' }, { name: 'moe', relation: 'uncle' }], isUncleMoe); @@ -251,7 +251,7 @@ _.isUndefined((window).missingVariable); /////////////////////////////////////////////////////////////////////////////////////// -var UncleMoe = {name: 'moe'}; +var UncleMoe = { name: 'moe' }; _.constant(UncleMoe)(); typeof _.now() === "number"; diff --git a/underscore/underscore.d.ts b/underscore/underscore.d.ts index 9c95e4bcb7..5fa693b00a 100644 --- a/underscore/underscore.d.ts +++ b/underscore/underscore.d.ts @@ -92,7 +92,7 @@ interface UnderscoreStatic { each( list: _.List, iterator: _.ListIterator, - context?: any): void; + context?: any): _.List; /** * @see _.each @@ -103,23 +103,23 @@ interface UnderscoreStatic { each( object: _.Dictionary, iterator: _.ObjectIterator, - context?: any): void; + context?: any): _.Dictionary; /** * @see _.each **/ forEach( list: _.List, - iterator: _.ListIterator, - context?: any): void; + iterator: _.ListIterator, + context?: any): _.List; /** * @see _.each **/ forEach( object: _.Dictionary, - iterator: _.ObjectIterator, - context?: any): void; + iterator: _.ObjectIterator, + context?: any): _.Dictionary; /** * Produces a new array of values by mapping each value in list through a transformation function @@ -629,11 +629,11 @@ interface UnderscoreStatic { * @return Number of values in `list`. **/ size(list: _.Collection): number; - + /** * Split array into two arrays: * one whose elements all satisfy predicate and one whose elements all do not satisfy predicate. - * @param array Array to split in two + * @param array Array to split in two. * @param iterator Filter iterator function for each element in `array`. * @param context `this` object in `iterator`, optional. * @return Array where Array[0] are the elements in `array` that satisfies the predicate, and Array[1] the elements that did not. @@ -979,7 +979,8 @@ interface UnderscoreStatic { /** * Partially apply a function by filling in any number of its arguments, without changing its dynamic this value. - * A close cousin of bind. + * A close cousin of bind. You may pass _ in your list of arguments to specify an argument that should not be + * pre-filled, but left open to supply at call-time. * @param fn Function to partially fill in arguments. * @param arguments The partial arguments. * @return `fn` with partially filled in arguments. @@ -1233,13 +1234,6 @@ interface UnderscoreStatic { **/ has(object: any, key: string): boolean; - /** - * Returns a function that will itself return the key property of any passed-in object - * @param key Property of the object - * @return Function which accept an object an returns the value of key in that object - **/ - property(key: string): (object: Object)=> any; - /** * Returns a predicate function that will tell you if a passed in object contains all of the key/value properties present in attrs. * @param attrs Object with key values pair @@ -1247,6 +1241,13 @@ interface UnderscoreStatic { **/ matches(attrs: T): _.ListIterator; + /** + * Returns a function that will itself return the key property of any passed-in object. + * @param key Property of the object. + * @return Function which accept an object an returns the value of key in that object. + **/ + property(key: string): (object: Object) => any; + /** * Performs an optimized deep comparison between the two objects, * to determine if they should be considered equal. @@ -1509,22 +1510,22 @@ interface Underscore { * Wrapped type `any[]`. * @see _.each **/ - each(iterator: _.ListIterator, context?: any): void; + each(iterator: _.ListIterator, context?: any): T[]; /** * @see _.each **/ - each(iterator: _.ObjectIterator, context?: any): void; + each(iterator: _.ObjectIterator, context?: any): T[]; /** * @see _.each **/ - forEach(iterator: _.ListIterator, context?: any): void; + forEach(iterator: _.ListIterator, context?: any): T[]; /** * @see _.each **/ - forEach(iterator: _.ObjectIterator, context?: any): void; + forEach(iterator: _.ObjectIterator, context?: any): T[]; /** * Wrapped type `any[]`. @@ -1862,6 +1863,12 @@ interface Underscore { **/ without(...values: T[]): T[]; + /** + * Wrapped type `any[]`. + * @see _.partition + **/ + partition(iterator: _.ListIterator, context?: any): T[][]; + /** * Wrapped type `any[][]`. * @see _.union @@ -2118,6 +2125,18 @@ interface Underscore { **/ has(key: string): boolean; + /** + * Wrapped type `any[]`. + * @see _.matches + **/ + matches(): _.ListIterator; + + /** + * Wrapped type `string`. + * @see _.property + **/ + property(): (object: Object) => any; + /** * Wrapped type `object`. * @see _.isEqual @@ -2224,6 +2243,12 @@ interface Underscore { **/ identity(): any; + /** + * Wrapped type `any`. + * @see _.constant + **/ + constant(): () => T; + /** * Wrapped type `number`. * @see _.times @@ -2298,22 +2323,22 @@ interface _Chain { * Wrapped type `any[]`. * @see _.each **/ - each(iterator: _.ListIterator, context?: any): _Chain; + each(iterator: _.ListIterator, context?: any): _Chain; /** * @see _.each **/ - each(iterator: _.ObjectIterator, context?: any): _Chain; + each(iterator: _.ObjectIterator, context?: any): _Chain; /** * @see _.each **/ - forEach(iterator: _.ListIterator, context?: any): _Chain; + forEach(iterator: _.ListIterator, context?: any): _Chain; /** * @see _.each **/ - forEach(iterator: _.ObjectIterator, context?: any): _Chain; + forEach(iterator: _.ObjectIterator, context?: any): _Chain; /** * Wrapped type `any[]`. @@ -2332,7 +2357,7 @@ interface _Chain { * @see _.map **/ map(iterator: _.ObjectIterator, context?: any): _ChainOfArrays; - + /** * Wrapped type `any[]`. * @see _.map @@ -2663,6 +2688,12 @@ interface _Chain { **/ without(...values: T[]): _Chain; + /** + * Wrapped type `any[]`. + * @see _.partition + **/ + partition(iterator: _.ListIterator, context?: any): _Chain; + /** * Wrapped type `any[][]`. * @see _.union @@ -2917,6 +2948,18 @@ interface _Chain { **/ has(key: string): _Chain; + /** + * Wrapped type `any[]`. + * @see _.matches + **/ + matches(): _Chain; + + /** + * Wrapped type `string`. + * @see _.property + **/ + property(): _Chain; + /** * Wrapped type `object`. * @see _.isEqual @@ -3023,6 +3066,12 @@ interface _Chain { **/ identity(): _Chain; + /** + * Wrapped type `any`. + * @see _.constant + **/ + constant(): _Chain; + /** * Wrapped type `number`. * @see _.times