Skip to content

Commit 40bfaf2

Browse files
authored
🤖 Merge PR #70989 [lodash] fix _.map to choose array overload signature given an array instead of tuple signature by @Ha-limLee
1 parent 48981c2 commit 40bfaf2

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

‎types/lodash/common/collection.d.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,7 @@ declare module "../index" {
11531153
* @param iteratee The function invoked per iteration.
11541154
* @return Returns the new mapped array.
11551155
*/
1156-
map<T extends readonly unknown[], TResult>(collection: T, iteratee: TupleIterator<T, TResult>): { [K in keyof T]: TResult };
1156+
map<T extends readonly [unknown, ...unknown[]], TResult>(collection: T, iteratee: TupleIterator<T, TResult>): { [K in keyof T]: TResult };
11571157
/**
11581158
* @see _.map
11591159
*/

‎types/lodash/lodash-tests.ts‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2752,6 +2752,13 @@ _.chain([1, 2, 3, 4]).unshift(5, 6); // $ExpectType CollectionChain<number>
27522752

27532753
// _.map
27542754
{
2755+
_.map([] as AbcObject[]); // $ExpectType AbcObject[]
2756+
_.map([] as AbcObject[], (value, index, collection) => {
2757+
value; // $ExpectType AbcObject
2758+
index; // $ExpectType number
2759+
collection; // $ExpectType AbcObject[]
2760+
return 0;
2761+
});
27552762
_.map(list); // $ExpectType AbcObject[]
27562763
// $ExpectType number[]
27572764
_.map(list, (value, index, collection) => {
@@ -5057,7 +5064,7 @@ fp.now(); // $ExpectType number
50575064
fp.random(1, 2); // $ExpectType number
50585065
fp.random(1)(2); // $ExpectType number
50595066

5060-
_.map([5, 5], _.random); // $ExpectType number[]
5067+
_.map([5, 5], _.random); // $ExpectType [number, number]
50615068
}
50625069

50635070
/**********
@@ -6841,7 +6848,7 @@ fp.now(); // $ExpectType number
68416848
fp.split("-")(null); // $ExpectType string[]
68426849
fp.split("-")("a-b-c"); // $ExpectType string[]
68436850

6844-
_.map(["abc", "def"], _.split); // $ExpectType string[][]
6851+
_.map(["abc", "def"], _.split); // $ExpectType [string[], string[]]
68456852
}
68466853

68476854
// _.startCase
@@ -6920,7 +6927,7 @@ fp.now(); // $ExpectType number
69206927
fp.trimChars(" ", " abc "); // $ExpectType string
69216928
fp.trimChars(" ")(" abc "); // $ExpectType string
69226929

6923-
_.map([" foo ", " bar "], _.trim); // $ExpectType string[]
6930+
_.map([" foo ", " bar "], _.trim); // $ExpectType [string, string]
69246931
}
69256932

69266933
// _.trimEnd
@@ -7008,7 +7015,7 @@ fp.now(); // $ExpectType number
70087015
_.chain("fred, barney, & pebbles").words(/[^, ]+/g); // $ExpectType CollectionChain<string>
70097016
fp.words("fred, barney, & pebbles"); // $ExpectType string[]
70107017

7011-
_.map(["fred, barney", "pebbles"], _.words); // $ExpectType string[][]
7018+
_.map(["fred, barney", "pebbles"], _.words); // $ExpectType [string[], string[]]
70127019
}
70137020

70147021
/********
@@ -7374,8 +7381,8 @@ fp.now(); // $ExpectType number
73747381
fp.rangeRight(1, 11); // $ExpectType number[]
73757382
fp.rangeRight(1)(11); // $ExpectType number[]
73767383

7377-
_.map([5, 5], _.range); // $ExpectType number[][]
7378-
_.map([5, 5], _.rangeRight); // $ExpectType number[][]
7384+
_.map([5, 5], _.range); // $ExpectType [number[], number[]]
7385+
_.map([5, 5], _.rangeRight); // $ExpectType [number[], number[]]
73797386
}
73807387

73817388
// _.runInContext

0 commit comments

Comments
 (0)