From 74d00ffad86123e2849b95adfb4f79da727fa86d Mon Sep 17 00:00:00 2001 From: Michael Heasell Date: Fri, 15 Feb 2019 11:51:57 +0000 Subject: [PATCH] Deduce return type from key in _.pluck --- types/underscore/index.d.ts | 5 +++-- types/underscore/underscore-tests.ts | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/types/underscore/index.d.ts b/types/underscore/index.d.ts index 72498e3591..8222ecbb74 100644 --- a/types/underscore/index.d.ts +++ b/types/underscore/index.d.ts @@ -2,6 +2,7 @@ // Project: http://underscorejs.org/ // Definitions by: Boris Yankov , Josh Baldwin , Christopher Currens , Cassey Lottman , Ard Timmerman // 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( + pluck( list: _.List, - propertyName: string): any[]; + propertyName: K): T[K][]; /** * Returns the maximum value in list. diff --git a/types/underscore/underscore-tests.ts b/types/underscore/underscore-tests.ts index 6175c1874b..c6086fe5c0 100644 --- a/types/underscore/underscore-tests.ts +++ b/types/underscore/underscore-tests.ts @@ -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'})