8000 🤖 Merge PR #72809 Lodash intersectioWith, fixing types in comparator'… · DefinitelyTyped/DefinitelyTyped@bdc81c6 · GitHub
[go: up one dir, main page]

Skip to content

Commit bdc81c6

Browse files
🤖 Merge PR #72809 Lodash intersectioWith, fixing types in comparator's parameters by @DanieleSalaris
1 parent f7539b2 commit bdc81c6

File tree

3 files changed

+44
-18
lines changed

3 files changed

+44
-18
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -760,15 +760,15 @@ declare module "../index" {
760760
* _.intersectionWith(objects, others, _.isEqual);
761761
* // => [{ 'x': 1, 'y': 2 }]
762762
*/
763-
intersectionWith<T1, T2>(array: List<T1> | null | undefined, values: List<T2>, comparator: Comparator2<T1, T2>): T1[];
763+
intersectionWith<T1, T2>(array: List<T1> | null | undefined, values: List<T2>, comparator: Comparator2<T1, T1 | T2>): T1[];
764764
/**
765765
* @see _.intersectionWith
766766
*/
767-
intersectionWith<T1, T2, T3>(array: List<T1> | null | undefined, values1: List<T2>, values2: List<T3>, comparator: Comparator2<T1, T2 | T3>): T1[];
767+
intersectionWith<T1, T2, T3>(array: List<T1> | null | undefined, values1: List<T2>, values2: List<T3>, comparator: Comparator2<T1, T1 | T2 | T3>): T1[];
768768
/**
769769
* @see _.intersectionWith
770770
*/
771-
intersectionWith<T1, T2, T3, T4>(array: List<T1> | null | undefined, values1: List<T2>, values2: List<T3>, ...values: Array<List<T4> | Comparator2<T1, T2 | T3 | T4>>): T1[];
771+
intersectionWith<T1, T2, T3, T4>(array: List<T1> | null | undefined, values1: List<T2>, values2: List<T3>, ...values: Array<List<T4> | Comparator2<T1, T1 | T2 | T3 | T4>>): T1[];
772772
/**
773773
* @see _.intersectionWith
774774
*/
@@ -778,7 +778,7 @@ declare module "../index" {
778778
/**
779779
* @see _.intersectionWith
780780
*/
781-
intersectionWith<T2>(values: List<T2>, comparator: Comparator2<T, T2>): Collection<T>;
781+
intersectionWith<T2>(values: List<T2>, comparator: Comparator2<T, T | T2>): Collection<T>;
782782
/**
783783
* @see _.intersectionWith
784784
*/
@@ -788,7 +788,7 @@ declare module "../index" {
788788
/**
789789
* @see _.intersectionWith
790790
*/
791-
intersectionWith<T2>(values: List<T2>, comparator: Comparator2<T, T2>): CollectionChain<T>;
791+
intersectionWith<T2>(values: List<T2>, comparator: Comparator2<T, T | T2>): CollectionChain<T>;
792792
/**
793793
* @see _.intersectionWith
794794
*/

‎types/lodash/fp.d.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,32 +1776,32 @@ declare namespace _ {
17761776
type LodashIntersectionBy1x5<T1> = (array: lodash.List<T1> | null) => T1[];
17771777
type LodashIntersectionBy1x6<T1, T2> = (iteratee: lodash.ValueIteratee<T1 | T2>) => T1[];
17781778
interface LodashIntersectionWith {
1779-
<T1, T2>(comparator: lodash.Comparator2<T1, T2>): LodashIntersectionWith1x1<T1, T2>;
1779+
<T1, T2>(comparator: lodash.Comparator2<T1, T1 | T2>): LodashIntersectionWith1x1<T1, T2>;
17801780
<T1>(comparator: lodash.__, array: lodash.List<T1> | null | undefined): LodashIntersectionWith1x2<T1>;
1781-
<T1, T2>(comparator: lodash.Comparator2<T1, T2>, array: lodash.List<T1> | null | undefined): LodashIntersectionWith1x3<T1, T2>;
1781+
<T1, T2>(comparator: lodash.Comparator2<T1, T1 | T2>, array: lodash.List<T1> | null | undefined): LodashIntersectionWith1x3<T1, T2>;
17821782
<T2>(comparator: lodash.__, array: lodash.__, values: lodash.List<T2>): LodashIntersectionWith1x4<T2>;
1783-
<T1, T2>(comparator: lodash.Comparator2<T1, T2>, array: lodash.__, values: lodash.List<T2>): LodashIntersectionWith1x5<T1>;
1783+
<T1, T2>(comparator: lodash.Comparator2<T1, T1 | T2>, array: lodash.__, values: lodash.List<T2>): LodashIntersectionWith1x5<T1>;
17841784
<T1, T2>(comparator: lodash.__, array: lodash.List<T1> | null | undefined, values: lodash.List<T2>): LodashIntersectionWith1x6<T1, T2>;
1785-
<T1, T2>(comparator: lodash.Comparator2<T1, T2>, array: lodash.List<T1> | null | undefined, values: lodash.List<T2>): T1[];
1785+
<T1, T2>(comparator: lodash.Comparator2<T1, T1 | T2>, array: lodash.List<T1> | null | undefined, values: lodash.List<T2>): T1[];
17861786
}
17871787
interface LodashIntersectionWith1x1<T1, T2> {
17881788
(array: lodash.List<T1> | null | undefined): LodashIntersectionWith1x3<T1, T2>;
17891789
(array: lodash.__, values: lodash.List<T2>): LodashIntersectionWith1x5<T1>;
17901790
(array: lodash.List<T1> | null | undefined, values: lodash.List<T2>): T1[];
17911791
}
17921792
interface LodashIntersectionWith1x2<T1> {
1793-
<T2>(comparator: lodash.Comparator2<T1, T2>): LodashIntersectionWith1x3<T1, T2>;
1793+
<T2>(comparator: lodash.Comparator2<T1, T1 | T2>): LodashIntersectionWith1x3<T1, T2>;
17941794
<T2>(comparator: lodash.__, values: lodash.List<T2>): LodashIntersectionWith1x6<T1, T2>;
1795-
<T2>(comparator: lodash.Comparator2<T1, T2>, values: lodash.List<T2>): T1[];
1795+
<T2>(comparator: lodash.Comparator2<T1, T1 | T2>, values: lodash.List<T2>): T1[];
17961796
}
17971797
type LodashIntersectionWith1x3<T1, T2> = (values: lodash.List<T2>) => T1[];
17981798
interface LodashIntersectionWith1x4<T2> {
1799-
<T1>(comparator: lodash.Comparator2<T1, T2>): LodashIntersectionWith1x5<T1>;
1799+
<T1>(comparator: lodash.Comparator2<T1, T1 | T2>): LodashIntersectionWith1x5<T1>;
18001800
<T1>(comparator: lodash.__, array: lodash.List<T1> | null | undefined): LodashIntersectionWith1x6<T1, T2>;
1801-
<T1>(comparator: lodash.Comparator2<T1, T2>, array: lodash.List<T1> | null | undefined): T1[];
1801+
<T1>(comparator: lodash.Comparator2<T1, T1 | T2>, array: lodash.List<T1> | null | undefined): T1[];
18021802
}
18031803
type LodashIntersectionWith1x5<T1> = (array: lodash.List<T1> | null | undefined) => T1[];
1804-
type LodashIntersectionWith1x6<T1, T2> = (comparator: lodash.Comparator2<T1, T2>) => T1[];
1804+
type LodashIntersectionWith1x6<T1, T2> = (comparator: lodash.Comparator2<T1, T1 | T2>) => T1[];
18051805
type LodashInvert = (object: object) => lodash.Dictionary<string>;
18061806
interface LodashInvertBy {
18071807
<T>(interatee: lodash.ValueIteratee<T>): LodashInvertBy1x1<T>;

‎types/lodash/lodash-tests.ts

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -782,23 +782,49 @@ _.chain([1, 2, 3, 4]).unshift(5, 6); // $ExpectType CollectionChain<number>
782782
// $ExpectType T1[]
783783
_.intersectionWith([t1], [t2], (a, b) => {
784784
a; // $ExpectType T1
785-
b; // $ExpectType T2
785+
b; // $ExpectType T1 | T2
786786
return true;
787787
});
788788
// $ExpectType Collection<T1>
789789
_([t1]).intersectionWith([t2], (a, b) => {
790790
a; // $ExpectType T1
791-
b; // $ExpectType T2
791+
b; // $ExpectType T1 | T2
792792
return true;
793793
});
794794
// $ExpectType CollectionChain<T1>
795795
_.chain([t1]).intersectionWith([t2], (a, b) => {
796796
a; // $ExpectType T1
797-
b; // $ExpectType T2
797+
b; // $ExpectType T1 | T2
798798
return true;
799799
});
800800

801-
fp.intersectionWith((a: T1, b: T2) => true)([t1])([t2]); // $ExpectType T1[]
801+
const a1 = [t1];
802+
const a2 = [t2];
803+
fp.intersectionWith((a: T1, b: T1 | T2) => true)([t1])([t2]); // $ExpectType T1[]
804+
// $ExpectType T1[]
805+
fp.intersectionWith<T1, T2>((a, b) => {
806+
a; // $ExpectType T1;
807+
b; // $ExpectType T1 | T2
808+
return true;
809+
}, a1, a2);
810+
// $ExpectType T1[]
811+
fp.intersectionWith<T1, T2>(_, a1, a2)((a, b) => {
812+
a; // $ExpectType T1;
813+
b; // $ExpectType T1 | T2
814+
return true;
815+
});
816+
// $ExpectType T1[]
817+
fp.intersectionWith(_, _, a2)(_, a1)((a, b) => {
818+
a; // $ExpectType T1;
819+
b; // $ExpectType T1 | T2
820+
return true;
821+
});
822+
// $ExpectType T1[]
823+
fp.intersectionWith(_, a1)(_, a2)((a, b) => {
824+
a; // $ExpectType T1;
825+
b; // $ExpectType T1 | T2
826+
return true;
827+
});
802828
}
803829

804830
// _.join

0 commit comments

Comments
 (0)
0