Deduce return type from key in _.pluck

This commit is contained in:
Michael Heasell
2019-02-26 00:10:49 +00:00
parent f9619dd065
commit 74d00ffad8
2 changed files with 4 additions and 3 deletions
+3 -2
View File
@@ -2,6 +2,7 @@
// Project: http://underscorejs.org/
// Definitions by: Boris Yankov <https://github.com/borisyankov>, Josh Baldwin <https://github.com/jbaldwin>, Christopher Currens <https://github.com/ccurrens>, Cassey Lottman <https://github.com/clottman>, Ard Timmerman <https://github.com/confususs>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
declare var _: _.UnderscoreStatic;
export = _;
@@ -553,9 +554,9 @@ declare module _ {
* @param propertyName The property to look for on each element within `list`.
* @return The list of elements within `list` that have the property `propertyName`.
**/
pluck<T extends {}>(
pluck<T extends {}, K extends keyof T>(
list: _.List<T>,
propertyName: string): any[];
propertyName: K): T[K][];
/**
* Returns the maximum value in list.
+1 -1
View File
@@ -520,7 +520,7 @@ function chain_tests() {
let numberObjects = [{property: 'odd', value: 1}, {property: 'even', value: 2}, {property: 'even', value: 0}];
let evenAndOddGroupedNumbers = _.chain(numberObjects)
.groupBy('property')
.mapObject((objects: any) => _.pluck(objects, 'value'))
.mapObject((objects) => _.pluck(objects, 'value'))
.value(); // { odd: [1], even: [0, 2] }
var matrixOfString : string[][] = _.chain({'foo' : '1', 'bar': '1'})