From 81821c1ff9eba77db5fbc1b7fda61f3ce3c19b17 Mon Sep 17 00:00:00 2001 From: Owen Hall Date: Mon, 18 Nov 2019 20:30:04 +0000 Subject: [PATCH] [underscore] Fixes sortBy on chained array wrapper (#40417) * underscore - Fix an issue where calling sortBy on a chained wrapper around Z[] claimed to return a Z. e.g. _.chain([1, 2, 3]).sortBy(x => -x).value() would claim to be of type number, not number[]. * underscore - Ensure length property is present on value of calling sortBy on chained, wrapped array. * underscore - Be more explicit that sortBy returns an array. That's its implementation behaviour, even if not provided with an array to begin with. * underscore - Revert unused generic type. --- types/underscore/index.d.ts | 4 ++-- types/underscore/underscore-tests.ts | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/types/underscore/index.d.ts b/types/underscore/index.d.ts index 087b3a121c..df1b84f3b2 100644 --- a/types/underscore/index.d.ts +++ b/types/underscore/index.d.ts @@ -5306,13 +5306,13 @@ declare module _ { * Wrapped type `any[]`. * @see _.sortBy **/ - sortBy(iterator?: _.ListIterator, context?: any): _Chain; + sortBy(iterator?: _.ListIterator, context?: any): _Chain; /** * Wrapped type `any[]`. * @see _.sortBy **/ - sortBy(iterator: string, context?: any): _Chain; + sortBy(iterator: string, context?: any): _Chain; /** * Wrapped type `any[]`. diff --git a/types/underscore/underscore-tests.ts b/types/underscore/underscore-tests.ts index 15d2413d35..49e7d59961 100644 --- a/types/underscore/underscore-tests.ts +++ b/types/underscore/underscore-tests.ts @@ -196,6 +196,11 @@ _.min(numbers); _.sortBy([1, 2, 3, 4, 5, 6], (num) => Math.sin(num)); +_([1, 2, 3]).chain() + .sortBy(x => -x) + .sortBy(x => -x) + .value().length; + _([1.3, 2.1, 2.4]).groupBy((e) => Math.floor(e)); _.groupBy([1.3, 2.1, 2.4], (num) => Math.floor(num).toString()); _.groupBy(['one', 'two', 'three'], 'length');