From 68c8f889da705eab6f043d0f18955b85d202d7df Mon Sep 17 00:00:00 2001 From: rayhaneh Date: Thu, 31 May 2018 10:04:04 -0400 Subject: [PATCH] Modified ramda differenceWith typing to accept lists of different types --- types/ramda/index.d.ts | 6 +++--- types/ramda/ramda-tests.ts | 14 +++++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/types/ramda/index.d.ts b/types/ramda/index.d.ts index 52e4becc10..52872755d0 100644 --- a/types/ramda/index.d.ts +++ b/types/ramda/index.d.ts @@ -523,9 +523,9 @@ declare namespace R { * Duplication is determined according to the value returned by applying the supplied predicate to two list * elements. */ - differenceWith(pred: (a: T, b: T) => boolean, list1: ReadonlyArray, list2: ReadonlyArray): T[]; - differenceWith(pred: (a: T, b: T) => boolean): (list1: ReadonlyArray, list2: ReadonlyArray) => T[]; - differenceWith(pred: (a: T, b: T) => boolean, list1: ReadonlyArray): (list2: ReadonlyArray) => T[]; + differenceWith(pred: (a: T1, b: T2) => boolean, list1: ReadonlyArray, list2: ReadonlyArray): T1[]; + differenceWith(pred: (a: T1, b: T2) => boolean): (list1: ReadonlyArray, list2: ReadonlyArray) => T1[]; + differenceWith(pred: (a: T1, b: T2) => boolean, list1: ReadonlyArray): (list2: ReadonlyArray) => T1[]; /* * Returns a new object that does not contain a prop property. diff --git a/types/ramda/ramda-tests.ts b/types/ramda/ramda-tests.ts index ee9e7512e1..27898696b7 100644 --- a/types/ramda/ramda-tests.ts +++ b/types/ramda/ramda-tests.ts @@ -1950,19 +1950,23 @@ class Rectangle { }; () => { - function cmp(x: any, y: any) { + function cmp1(x: any, y: any) { return x.a === y.a; } + function cmp2(x: any, y: any) { + return x.a === y.b; + } + const l1 = [{a: 1}, {a: 2}, {a: 3}]; const l2 = [{a: 3}, {a: 4}]; - R.differenceWith(cmp, l1, l2); // => [{a: 1}, {a: 2}] + const l3 = [{b: 3}, {b: 4}]; + R.differenceWith(cmp1, l1, l2); // => [{a: 1}, {a: 2}] - const differenceWithCurried1 = R.differenceWith(cmp); + const differenceWithCurried1 = R.differenceWith(cmp1); differenceWithCurried1(l1, l2); // =>[{a: 1}, {a: 2}] - const differenceWithCurried2 = R.differenceWith(cmp, l1); - differenceWithCurried2(l2); // =>[{a: 1}, {a: 2}] + R.differenceWith(cmp2, l1, l3); // => [{a: 1}, {a: 2}] }; () => {