underscore: fix chain with Dictionary<T>

I added a test for this, it would previously fail to compile.

Also, using `_.values()` on a Dictionary would lose strong typing on the result, returning `any[]`. This now properly returns `T[]` in that case.
This commit is contained in:
Andrei Alecu
2016-01-06 19:46:26 +02:00
parent 04b1abdcfe
commit 1e3835e65e
2 changed files with 25 additions and 0 deletions
+17
View File
@@ -479,3 +479,20 @@ _.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 }
},
empty = {};
_.chain(dictionaryLike).values().filter((r) => {
return r.value >= 8;
}).map((r) => {
return [r.title, true];
}).object().value();
_.values<{title: string, value: number}>(dictionaryLike);
}
+8
View File
@@ -1192,6 +1192,13 @@ interface UnderscoreStatic {
**/
keys(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<T>(object: _.Dictionary<T>): T[];
/**
* Return all of the values of the object's properties.
* @param object Retrieve the values of all the properties on this object.
@@ -1641,6 +1648,7 @@ interface UnderscoreStatic {
* @return Wrapped `obj`.
**/
chain<T>(obj: T[]): _Chain<T>;
chain<T>(obj: _.Dictionary<T>): _Chain<T>;
chain<T extends {}>(obj: T): _Chain<T>;
}