[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.
This commit is contained in:
Owen Hall
2019-11-18 12:30:04 -08:00
committed by Sheetal Nandi
parent 1111ada737
commit 81821c1ff9
2 changed files with 7 additions and 2 deletions
+2 -2
View File
@@ -5306,13 +5306,13 @@ declare module _ {
* Wrapped type `any[]`.
* @see _.sortBy
**/
sortBy(iterator?: _.ListIterator<T, any>, context?: any): _Chain<T>;
sortBy(iterator?: _.ListIterator<T, any>, context?: any): _Chain<T, T[]>;
/**
* Wrapped type `any[]`.
* @see _.sortBy
**/
sortBy(iterator: string, context?: any): _Chain<T>;
sortBy(iterator: string, context?: any): _Chain<T, T[]>;
/**
* Wrapped type `any[]`.
+5
View File
@@ -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');