From a64e763292d2a0dddc7e1762fc4cb299bef5a34a Mon Sep 17 00:00:00 2001 From: Fumiaki MATSUSHIMA Date: Tue, 9 Jul 2019 01:59:01 +0900 Subject: [PATCH] lodash: Consider rest operator for intersectionBy (#36610) --- types/lodash/common/array.d.ts | 21 +++++++++++++-------- types/lodash/lodash-tests.ts | 15 +++++++++++++++ types/lodash/ts3.1/common/array.d.ts | 4 ++++ types/lodash/ts3.1/lodash-tests.ts | 10 ++++++++++ 4 files changed, 42 insertions(+), 8 deletions(-) diff --git a/types/lodash/common/array.d.ts b/types/lodash/common/array.d.ts index 6d4aff3056..a16cad8301 100644 --- a/types/lodash/common/array.d.ts +++ b/types/lodash/common/array.d.ts @@ -1205,6 +1205,11 @@ declare module "../index" { array?: List | null, ...values: Array> ): T[]; + + /** + * @see _.intersectionBy + */ + intersectionBy(...values: Array | ValueIteratee>): T[]; } interface LoDashImplicitWrapper { @@ -1240,10 +1245,10 @@ declare module "../index" { /** * @see _.intersectionBy */ - intersectionBy( - this: LoDashImplicitWrapper | null | undefined>, - ...values: Array> - ): LoDashImplicitWrapper; + intersectionBy( + this: LoDashImplicitWrapper | null | undefined>, + ...values: Array | ValueIteratee> + ): LoDashImplicitWrapper; } interface LoDashExplicitWrapper { @@ -1279,10 +1284,10 @@ declare module "../index" { /** * @see _.intersectionBy */ - intersectionBy( - this: LoDashExplicitWrapper | null | undefined>, - ...values: Array> - ): LoDashExplicitWrapper; + intersectionBy( + this: LoDashExplicitWrapper | null | undefined>, + ...values: Array | ValueIteratee> + ): LoDashExplicitWrapper; } // intersectionWith diff --git a/types/lodash/lodash-tests.ts b/types/lodash/lodash-tests.ts index 0b14029b64..f589cef369 100644 --- a/types/lodash/lodash-tests.ts +++ b/types/lodash/lodash-tests.ts @@ -624,6 +624,11 @@ _.chain([1, 2, 3, 4]).unshift(5, 6); // $ExpectType LoDashExplicitWrapper { + value; // $ExpectType AbcObject + return 0; + }); _.chain(list).intersectionBy(list); // $ExpectType LoDashExplicitWrapper _.chain(list).intersectionBy(list, "a"); // $ExpectType LoDashExplicitWrapper @@ -661,11 +666,21 @@ _.chain([1, 2, 3, 4]).unshift(5, 6); // $ExpectType LoDashExplicitWrapper + _([t1]).intersectionBy(...[[t2]], (value) => { + value; // $ExpectType T1 | T2 + return {}; + }); // $ExpectType LoDashExplicitWrapper _.chain([t1]).intersectionBy([t2], (value) => { value; // $ExpectType T1 | T2 return {}; }); + // $ExpectType LoDashExplicitWrapper + _.chain([t1]).intersectionBy(...[[t2]], (value) => { + value; // $ExpectType T1 | T2 + return {}; + }); } // _.intersectionWith diff --git a/types/lodash/ts3.1/common/array.d.ts b/types/lodash/ts3.1/common/array.d.ts index 13e4e3d920..f8c86c3e68 100644 --- a/types/lodash/ts3.1/common/array.d.ts +++ b/types/lodash/ts3.1/common/array.d.ts @@ -713,6 +713,10 @@ declare module "../index" { * @see _.intersectionBy */ intersectionBy(array?: List | null, ...values: Array>): T[]; + /** + * @see _.intersectionBy + */ + intersectionBy(...values: Array | ValueIteratee>): T[]; } interface Collection { /** diff --git a/types/lodash/ts3.1/lodash-tests.ts b/types/lodash/ts3.1/lodash-tests.ts index ac63f46640..851f9ff4d6 100644 --- a/types/lodash/ts3.1/lodash-tests.ts +++ b/types/lodash/ts3.1/lodash-tests.ts @@ -615,6 +615,11 @@ _.chain([1, 2, 3, 4]).unshift(5, 6); // $ExpectType CollectionChain value; // $ExpectType AbcObject return 0; }); + // $ExpectType AbcObject[] + _.intersectionBy(...[list], (value) => { + value; // $ExpectType AbcObject + return 0; + }); _(list).intersectionBy(list); // $ExpectType Collection _(list).intersectionBy(list, "a"); // $ExpectType Collection @@ -635,6 +640,11 @@ _.chain([1, 2, 3, 4]).unshift(5, 6); // $ExpectType CollectionChain value; // $ExpectType AbcObject return null; }); + // $ExpectType CollectionChain + _.chain(list).intersectionBy(...[list], (value) => { + value; // $ExpectType AbcObject + return null; + }); fp.intersectionBy("a", list, list); // $ExpectType AbcObject[] fp.intersectionBy("a", list, list); // $ExpectType AbcObject[]