diff --git a/underscore/underscore-tests.ts b/underscore/underscore-tests.ts index 051e000d0..74cef85ec 100644 --- a/underscore/underscore-tests.ts +++ b/underscore/underscore-tests.ts @@ -479,3 +479,25 @@ _.chain(obj).map(function (value, key) { empty[key] = value; console.log("vk", value, key); }); + +function strong_typed_values_tests() { + var dictionaryLike: { [k: string] : {title: string, value: number} } = { + 'test' : { title: 'item1', value: 5 }, + 'another' : { title: 'item2', value: 8 }, + 'third' : { title: 'item3', value: 10 } + }; + + _.chain(dictionaryLike).values().filter((r) => { + return r.value >= 8; + }).map((r) => { + return [r.title, true]; + }).object().value(); + + var x: number = _(dictionaryLike).chain().filter((x) => { + console.log(x.title); + console.log(x.value.toFixed()); + return x.title == 'item1'; + }).size().value(); + + _.values<{title: string, value: number}>(dictionaryLike); +} diff --git a/underscore/underscore.d.ts b/underscore/underscore.d.ts index ace0392b7..66b2e8f3e 100644 --- a/underscore/underscore.d.ts +++ b/underscore/underscore.d.ts @@ -76,6 +76,7 @@ interface UnderscoreStatic { * as the first parameter can be invoked through this function. * @param key First argument to Underscore object functions. **/ + (value: _.Dictionary): Underscore; (value: Array): Underscore; (value: T): Underscore; @@ -1233,6 +1234,13 @@ interface UnderscoreStatic { **/ allKeys(object: any): string[]; + /** + * Return all of the values of the object's properties. + * @param object Retrieve the values of all the properties on this object. + * @return List of all the values on `object`. + **/ + values(object: _.Dictionary): T[]; + /** * Return all of the values of the object's properties. * @param object Retrieve the values of all the properties on this object. @@ -1700,6 +1708,7 @@ interface UnderscoreStatic { * @return Wrapped `obj`. **/ chain(obj: T[]): _Chain; + chain(obj: _.Dictionary): _Chain; chain(obj: T): _Chain; } @@ -2914,7 +2923,7 @@ interface _Chain { * Wrapped type `any`. * @see _.size **/ - size(): _Chain; + size(): _ChainSingle; /********* * Arrays *