From 578aabef155f9aa1d20237face4261ee193c75ef Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 18 Apr 2019 14:39:40 -0700 Subject: [PATCH] Simplify differenceBy/differenceWith I only changed the Imp/Exp overloads, because those are the ones that create significant numbers of types. The normal case is still fully typed, but when passing multiple comparison arrays, they are all typed as `List`, and the iteratee is not checked for compatibility with their types. You should never use multiple comparison arrays. Brings type count down 18k, from 452k to 434k. --- types/lodash/common/array.d.ts | 26 ++++++-------------------- types/lodash/lodash-tests.ts | 12 ++++++------ 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/types/lodash/common/array.d.ts b/types/lodash/common/array.d.ts index 4e7bf47511..9e6bd31c9f 100644 --- a/types/lodash/common/array.d.ts +++ b/types/lodash/common/array.d.ts @@ -46,22 +46,12 @@ declare module "../index" { differenceBy( array: List | null | undefined, ...values: Array> ): T[]; } interface Imp { - differenceBy( this: Imp | null | undefined>, values: List, iteratee: ValueIteratee ): Imp; - differenceBy( this: Imp | null | undefined>, values1: List, values2: List, iteratee: ValueIteratee ): Imp; - differenceBy( this: Imp | null | undefined>, values1: List, values2: List, values3: List, iteratee: ValueIteratee ): Imp; - differenceBy( this: Imp | null | undefined>, values1: List, values2: List, values3: List, values4: List, iteratee: ValueIteratee ): Imp; - differenceBy( this: Imp | null | undefined>, values1: List, values2: List, values3: List, values4: List, values5: List, iteratee: ValueIteratee ): Imp; - differenceBy( this: Imp | null | undefined>, values1: List, values2: List, values3: List, values4: List, values5: List, ...values: Array | ValueIteratee> ): Imp; - differenceBy( this: Imp | null | undefined>, ...values: Array> ): Imp; + differenceBy( this: Imp | null | undefined>, values1: T2, iteratee?: ValueIteratee ): Imp; + differenceBy( this: Imp | null | undefined>, ...values: Array | ValueIteratee> ): Imp; } interface Exp { - differenceBy( this: Exp | null | undefined>, values: List, iteratee: ValueIteratee ): Exp; - differenceBy( this: Exp | null | undefined>, values1: List, values2: List, iteratee: ValueIteratee ): Exp; - differenceBy( this: Exp | null | undefined>, values1: List, values2: List, values3: List, iteratee: ValueIteratee ): Exp; - differenceBy( this: Exp | null | undefined>, values1: List, values2: List, values3: List, values4: List, iteratee: ValueIteratee ): Exp; - differenceBy( this: Exp | null | undefined>, values1: List, values2: List, values3: List, values4: List, values5: List, iteratee: ValueIteratee ): Exp; - differenceBy( this: Exp | null | undefined>, values1: List, values2: List, values3: List, values4: List, values5: List, ...values: Array | ValueIteratee> ): Exp; - differenceBy( this: Exp | null | undefined>, ...values: Array> ): Exp; + differenceBy( this: Exp | null | undefined>, values1: T2, iteratee?: ValueIteratee ): Exp; + differenceBy(this: Exp | null | undefined>, ...values: Array | ValueIteratee> ): Exp; } interface Stat { differenceWith( array: List | null | undefined, values: List, comparator: Comparator2 ): T1[]; @@ -71,15 +61,11 @@ declare module "../index" { } interface Imp { differenceWith( this: Imp | null | undefined>, values: List, comparator: Comparator2 ): Imp; - differenceWith( this: Imp | null | undefined>, values1: List, values2: List, comparator: Comparator2 ): Imp; - differenceWith( this: Imp | null | undefined>, values1: List, values2: List, ...values: Array | Comparator2> ): Imp; - differenceWith( this: Imp | null | undefined>, ...values: Array> ): Imp; + differenceWith( this: Imp | null | undefined>, ...values: Array | Comparator2> ): Imp; } interface Exp { differenceWith( this: Exp | null | undefined>, values: List, comparator: Comparator2 ): Exp; - differenceWith( this: Exp | null | undefined>, values1: List, values2: List, comparator: Comparator2 ): Exp; - differenceWith( this: Exp | null | undefined>, values1: List, values2: List, ...values: Array | Comparator2> ): Exp; - differenceWith( this: Exp | null | undefined>, ...values: Array> ): Exp; + differenceWith( this: Exp | null | undefined>, ...values: Array | Comparator2> ): Exp; } interface Stat { drop(array: List | null | undefined, n?: number): T[]; diff --git a/types/lodash/lodash-tests.ts b/types/lodash/lodash-tests.ts index bbf12098e4..4d29437c5d 100644 --- a/types/lodash/lodash-tests.ts +++ b/types/lodash/lodash-tests.ts @@ -115,17 +115,17 @@ _.chain([1, 2, 3, 4]).unshift(5, 6); // $ExpectType LoDashExplicitWrapper _(list).differenceBy(listParam, arrayParam, listParam, arrayParam, listParam, valueIterator); // $ExpectType LoDashImplicitWrapper // $ExpectType LoDashImplicitWrapper - _(list).differenceBy(arrayParam, listParam, arrayParam, listParam, arrayParam, listParam, valueIterator); + _(list).differenceBy(arrayParam, listParam, arrayParam, listParam, arrayParam, listParam, valueIterator); _(list).differenceBy(listParam, "a"); // $ExpectType LoDashImplicitWrapper _(list).differenceBy(listParam, arrayParam, listParam, arrayParam, listParam, "a"); // $ExpectType LoDashImplicitWrapper // $ExpectType LoDashImplicitWrapper - _(list).differenceBy(arrayParam, listParam, arrayParam, listParam, arrayParam, listParam, "a"); + _(list).differenceBy(arrayParam, listParam, arrayParam, listParam, arrayParam, listParam, "a"); _(list).differenceBy(listParam, {a: 1}); // $ExpectType LoDashImplicitWrapper _(list).differenceBy(listParam, arrayParam, listParam, arrayParam, listParam, {a: 1}); // $ExpectType LoDashImplicitWrapper // $ExpectType LoDashImplicitWrapper - _(list).differenceBy(arrayParam, listParam, arrayParam, listParam, arrayParam, listParam, {a: 1}); + _(list).differenceBy(arrayParam, listParam, arrayParam, listParam, arrayParam, listParam, {a: 1}); _.chain(list).differenceBy(arrayParam); // $ExpectType LoDashExplicitWrapper _.chain(list).differenceBy(listParam, arrayParam, listParam, arrayParam, listParam, arrayParam); // $ExpectType LoDashExplicitWrapper @@ -133,17 +133,17 @@ _.chain([1, 2, 3, 4]).unshift(5, 6); // $ExpectType LoDashExplicitWrapper _.chain(list).differenceBy(arrayParam, listParam, arrayParam, listParam, arrayParam, valueIterator); // $ExpectType LoDashExplicitWrapper // $ExpectType LoDashExplicitWrapper - _.chain(list).differenceBy(listParam, arrayParam, listParam, arrayParam, listParam, arrayParam, valueIterator); + _.chain(list).differenceBy(listParam, arrayParam, listParam, arrayParam, listParam, arrayParam, valueIterator); _.chain(list).differenceBy(arrayParam, "a"); // $ExpectType LoDashExplicitWrapper _.chain(list).differenceBy(arrayParam, listParam, arrayParam, listParam, arrayParam, "a"); // $ExpectType LoDashExplicitWrapper // $ExpectType LoDashExplicitWrapper - _.chain(list).differenceBy(listParam, arrayParam, listParam, arrayParam, listParam, arrayParam, "a"); + _.chain(list).differenceBy(listParam, arrayParam, listParam, arrayParam, listParam, arrayParam, "a"); _.chain(list).differenceBy(arrayParam, {a: 1}); // $ExpectType LoDashExplicitWrapper _.chain(list).differenceBy(arrayParam, listParam, arrayParam, listParam, arrayParam, {a: 1}); // $ExpectType LoDashExplicitWrapper // $ExpectType LoDashExplicitWrapper - _.chain(list).differenceBy(listParam, arrayParam, listParam, arrayParam, listParam, arrayParam, {a: 1}); + _.chain(list).differenceBy(listParam, arrayParam, listParam, arrayParam, listParam, arrayParam, {a: 1}); fp.differenceBy(valueIterator, list, arrayParam); // $ExpectType AbcObject[] fp.differenceBy(valueIterator)(list)(listParam); // $ExpectType AbcObject[]