From 9c21b9040cc91bbc84cf4dd0288cf4075809e374 Mon Sep 17 00:00:00 2001 From: Max Bogue Date: Wed, 9 Jan 2019 10:34:27 -0600 Subject: [PATCH] Attempt filtering out StringIterator. --- types/lodash/common/collection.d.ts | 2 +- types/lodash/fp.d.ts | 137 ++++++++++------------------ types/lodash/lodash-tests.ts | 4 +- types/lodash/scripts/generate-fp.ts | 1 + 4 files changed, 54 insertions(+), 90 deletions(-) diff --git a/types/lodash/common/collection.d.ts b/types/lodash/common/collection.d.ts index 024116adc8..641a4f92f7 100644 --- a/types/lodash/common/collection.d.ts +++ b/types/lodash/common/collection.d.ts @@ -215,7 +215,7 @@ declare module "../index" { * @return Returns the new filtered array. */ filter( - collection: string | string[] | null | undefined, + collection: string | null | undefined, predicate?: StringIterator ): string[]; diff --git a/types/lodash/fp.d.ts b/types/lodash/fp.d.ts index a31b8b459d..68084f1c8d 100644 --- a/types/lodash/fp.d.ts +++ b/types/lodash/fp.d.ts @@ -616,20 +616,15 @@ declare namespace _ { (iteratee: (value: T) => any): LodashForEach1x1; (iteratee: lodash.__, collection: ReadonlyArray): LodashForEach1x2; (iteratee: (value: T) => any, collection: ReadonlyArray): T[]; - (iteratee: (value: string) => any): LodashForEach2x1; - (iteratee: lodash.__, collection: string): LodashForEach2x2; - (iteratee: (value: string) => any, collection: string): string; - (iteratee: lodash.__, collection: lodash.List): LodashForEach3x2; + (iteratee: lodash.__, collection: lodash.List): LodashForEach2x2; (iteratee: (value: T) => any, collection: lodash.List): lodash.List; - (iteratee: lodash.__, collection: T): LodashForEach4x2; + (iteratee: lodash.__, collection: T): LodashForEach3x2; (iteratee: (value: T[keyof T]) => any, collection: T): T; - (iteratee: lodash.__, collection: TArray & (T[] | null | undefined)): LodashForEach5x2; + (iteratee: lodash.__, collection: TArray & (T[] | null | undefined)): LodashForEach4x2; (iteratee: (value: T) => any, collection: TArray & (T[] | null | undefined)): TArray; - (iteratee: lodash.__, collection: TString): LodashForEach6x2; - (iteratee: (value: string) => any, collection: TString): TString; - | null | undefined>(iteratee: lodash.__, collection: TList & (lodash.List | null | undefined)): LodashForEach7x2; + | null | undefined>(iteratee: lodash.__, collection: TList & (lodash.List | null | undefined)): LodashForEach5x2; | null | undefined>(iteratee: (value: T) => any, collection: TList & (lodash.List | null | undefined)): TList; - (iteratee: lodash.__, collection: T | null | undefined): LodashForEach8x2; + (iteratee: lodash.__, collection: T | null | undefined): LodashForEach6x2; (iteratee: (value: T[keyof T]) => any, collection: T | null | undefined): T | null | undefined; } interface LodashForEach1x1 { @@ -641,35 +636,24 @@ declare namespace _ { (collection: T1 | null | undefined): T1 | null | undefined; } type LodashForEach1x2 = (iteratee: (value: T) => any) => T[]; - interface LodashForEach2x1 { - (collection: string): string; - (collection: TString): TString; - } - type LodashForEach2x2 = (iteratee: (value: string) => any) => string; - type LodashForEach3x2 = (iteratee: (value: T) => any) => lodash.List; - type LodashForEach4x2 = (iteratee: (value: T[keyof T]) => any) => T; - type LodashForEach5x2 = (iteratee: (value: T) => any) => TArray; - type LodashForEach6x2 = (iteratee: (value: string) => any) => TString; - type LodashForEach7x2 = (iteratee: (value: T) => any) => TList; - type LodashForEach8x2 = (iteratee: (value: T[keyof T]) => any) => T | null | undefined; + type LodashForEach2x2 = (iteratee: (value: T) => any) => lodash.List; + type LodashForEach3x2 = (iteratee: (value: T[keyof T]) => any) => T; + type LodashForEach4x2 = (iteratee: (value: T) => any) => TArray; + type LodashForEach5x2 = (iteratee: (value: T) => any) => TList; + type LodashForEach6x2 = (iteratee: (value: T[keyof T]) => any) => T | null | undefined; interface LodashForEachRight { (iteratee: (value: T) => any): LodashForEachRight1x1; (iteratee: lodash.__, collection: ReadonlyArray): LodashForEachRight1x2; (iteratee: (value: T) => any, collection: ReadonlyArray): T[]; - (iteratee: (value: string) => any): LodashForEachRight2x1; - (iteratee: lodash.__, collection: string): LodashForEachRight2x2; - (iteratee: (value: string) => any, collection: string): string; - (iteratee: lodash.__, collection: lodash.List): LodashForEachRight3x2; + (iteratee: lodash.__, collection: lodash.List): LodashForEachRight2x2; (iteratee: (value: T) => any, collection: lodash.List): lodash.List; - (iteratee: lodash.__, collection: T): LodashForEachRight4x2; + (iteratee: lodash.__, collection: T): LodashForEachRight3x2; (iteratee: (value: T[keyof T]) => any, collection: T): T; - (iteratee: lodash.__, collection: TArray & (T[] | null | undefined)): LodashForEachRight5x2; + (iteratee: lodash.__, collection: TArray & (T[] | null | undefined)): LodashForEachRight4x2; (iteratee: (value: T) => any, collection: TArray & (T[] | null | undefined)): TArray; - (iteratee: lodash.__, collection: TString): LodashForEachRight6x2; - (iteratee: (value: string) => any, collection: TString): TString; - | null | undefined>(iteratee: lodash.__, collection: TList & (lodash.List | null | undefined)): LodashForEachRight7x2; + | null | undefined>(iteratee: lodash.__, collection: TList & (lodash.List | null | undefined)): LodashForEachRight5x2; | null | undefined>(iteratee: (value: T) => any, collection: TList & (lodash.List | null | undefined)): TList; - (iteratee: lodash.__, collection: T | null | undefined): LodashForEachRight8x2; + (iteratee: lodash.__, collection: T | null | undefined): LodashForEachRight6x2; (iteratee: (value: T[keyof T]) => any, collection: T | null | undefined): T | null | undefined; } interface LodashForEachRight1x1 { @@ -681,17 +665,11 @@ declare namespace _ { (collection: T1 | null | undefined): T1 | null | undefined; } type LodashForEachRight1x2 = (iteratee: (value: T) => any) => T[]; - interface LodashForEachRight2x1 { - (collection: string): string; - (collection: TString): TString; - } - type LodashForEachRight2x2 = (iteratee: (value: string) => any) => string; - type LodashForEachRight3x2 = (iteratee: (value: T) => any) => lodash.List; - type LodashForEachRight4x2 = (iteratee: (value: T[keyof T]) => any) => T; - type LodashForEachRight5x2 = (iteratee: (value: T) => any) => TArray; - type LodashForEachRight6x2 = (iteratee: (value: string) => any) => TString; - type LodashForEachRight7x2 = (iteratee: (value: T) => any) => TList; - type LodashForEachRight8x2 = (iteratee: (value: T[keyof T]) => any) => T | null | undefined; + type LodashForEachRight2x2 = (iteratee: (value: T) => any) => lodash.List; + type LodashForEachRight3x2 = (iteratee: (value: T[keyof T]) => any) => T; + type LodashForEachRight4x2 = (iteratee: (value: T) => any) => TArray; + type LodashForEachRight5x2 = (iteratee: (value: T) => any) => TList; + type LodashForEachRight6x2 = (iteratee: (value: T[keyof T]) => any) => T | null | undefined; interface LodashEndsWith { (target: string): LodashEndsWith1x1; (target: lodash.__, string: string): LodashEndsWith1x2; @@ -917,29 +895,24 @@ declare namespace _ { type LodashFill2x13 = (end: number) => lodash.List; type LodashFill2x14 = (start: number) => lodash.List; interface LodashFilter { - (predicate: (value: string) => boolean): LodashFilter1x1; - (predicate: lodash.__, collection: string | string[] | null | undefined): LodashFilter1x2; - (predicate: (value: string) => boolean, collection: string | string[] | null | undefined): string[]; - (predicate: lodash.ValueIteratorTypeGuard): LodashFilter2x1; - (predicate: lodash.__, collection: lodash.List | null | undefined): LodashFilter2x2; + (predicate: lodash.ValueIteratorTypeGuard): LodashFilter1x1; + (predicate: lodash.__, collection: lodash.List | null | undefined): LodashFilter1x2; (predicate: lodash.ValueIteratorTypeGuard, collection: lodash.List | null | undefined): S[]; - (predicate: lodash.ValueIterateeCustom): LodashFilter3x1; + (predicate: lodash.ValueIterateeCustom): LodashFilter2x1; (predicate: lodash.ValueIterateeCustom, collection: lodash.List | null | undefined): T[]; - (predicate: lodash.ValueIteratorTypeGuard): LodashFilter4x1; - (predicate: lodash.__, collection: T | null | undefined): LodashFilter4x2; + (predicate: lodash.ValueIteratorTypeGuard): LodashFilter3x1; + (predicate: lodash.__, collection: T | null | undefined): LodashFilter3x2; (predicate: lodash.ValueIteratorTypeGuard, collection: T | null | undefined): S[]; (predicate: lodash.ValueIterateeCustom, collection: T | null | undefined): Array; } - type LodashFilter1x1 = (collection: string | string[] | null | undefined) => string[]; - type LodashFilter1x2 = (predicate: (value: string) => boolean) => string[]; - type LodashFilter2x1 = (collection: lodash.List | null | undefined) => S[]; - interface LodashFilter2x2 { + type LodashFilter1x1 = (collection: lodash.List | null | undefined) => S[]; + interface LodashFilter1x2 { (predicate: lodash.ValueIteratorTypeGuard): S[]; (predicate: lodash.ValueIterateeCustom): T[]; } - type LodashFilter3x1 = (collection: lodash.List | object | null | undefined) => T[]; - type LodashFilter4x1 = (collection: T | null | undefined) => S[]; - interface LodashFilter4x2 { + type LodashFilter2x1 = (collection: lodash.List | object | null | undefined) => T[]; + type LodashFilter3x1 = (collection: T | null | undefined) => S[]; + interface LodashFilter3x2 { (predicate: lodash.ValueIteratorTypeGuard): S[]; (predicate: lodash.ValueIterateeCustom): Array; } @@ -2131,45 +2104,40 @@ declare namespace _ { type LodashMapKeys2x1 = (object: T | null | undefined) => lodash.Dictionary; type LodashMapKeys2x2 = (iteratee: lodash.ValueIteratee) => lodash.Dictionary; interface LodashMapValues { - (callback: (value: string) => TResult): LodashMapValues1x1; - (callback: lodash.__, obj: string | null | undefined): LodashMapValues1x2; - (callback: (value: string) => TResult, obj: string | null | undefined): lodash.NumericDictionary; - (callback: (value: T) => TResult): LodashMapValues2x1; - (callbackOrIterateeOrIterateeOrIteratee: lodash.__, obj: lodash.Dictionary | lodash.NumericDictionary | null | undefined): LodashMapValues2x2; + (callback: (value: T) => TResult): LodashMapValues1x1; + (callbackOrIterateeOrIterateeOrIteratee: lodash.__, obj: lodash.Dictionary | lodash.NumericDictionary | null | undefined): LodashMapValues1x2; (callback: (value: T) => TResult, obj: lodash.Dictionary | lodash.NumericDictionary | null | undefined): lodash.Dictionary; - (callback: (value: T[keyof T]) => TResult): LodashMapValues3x1; - (callbackOrIterateeOrIteratee: lodash.__, obj: T | null | undefined): LodashMapValues3x2; + (callback: (value: T[keyof T]) => TResult): LodashMapValues2x1; + (callbackOrIterateeOrIteratee: lodash.__, obj: T | null | undefined): LodashMapValues2x2; (callback: (value: T[keyof T]) => TResult, obj: T | null | undefined): { [P in keyof T]: TResult }; - (iteratee: object): LodashMapValues4x1; + (iteratee: object): LodashMapValues3x1; (iteratee: object, obj: lodash.Dictionary | lodash.NumericDictionary | null | undefined): lodash.Dictionary; (iteratee: object, obj: T | null | undefined): { [P in keyof T]: boolean }; - (iteratee: TKey): LodashMapValues6x1; + (iteratee: TKey): LodashMapValues5x1; (iteratee: TKey, obj: lodash.Dictionary | lodash.NumericDictionary | null | undefined): lodash.Dictionary; - (iteratee: string): LodashMapValues7x1; + (iteratee: string): LodashMapValues6x1; (iteratee: string, obj: lodash.Dictionary | lodash.NumericDictionary | null | undefined): lodash.Dictionary; (iteratee: string, obj: T | null | undefined): { [P in keyof T]: any }; } - type LodashMapValues1x1 = (obj: string | null | undefined) => lodash.NumericDictionary; - type LodashMapValues1x2 = (callback: (value: string) => TResult) => lodash.NumericDictionary; - type LodashMapValues2x1 = (obj: lodash.Dictionary | lodash.NumericDictionary | null | undefined) => lodash.Dictionary; - interface LodashMapValues2x2 { + type LodashMapValues1x1 = (obj: lodash.Dictionary | lodash.NumericDictionary | null | undefined) => lodash.Dictionary; + interface LodashMapValues1x2 { (callback: (value: T) => TResult): lodash.Dictionary; (iteratee: object): lodash.Dictionary; (iteratee: TKey): lodash.Dictionary; (iteratee: string): lodash.Dictionary; } - type LodashMapValues3x1 = (obj: T | null | undefined) => { [P in keyof T]: TResult }; - interface LodashMapValues3x2 { + type LodashMapValues2x1 = (obj: T | null | undefined) => { [P in keyof T]: TResult }; + interface LodashMapValues2x2 { (callback: (value: T[keyof T]) => TResult): { [P in keyof T]: TResult }; (iteratee: object): { [P in keyof T]: boolean }; (iteratee: string): { [P in keyof T]: any }; } - interface LodashMapValues4x1 { + interface LodashMapValues3x1 { (obj: lodash.Dictionary | lodash.NumericDictionary | null | undefined): lodash.Dictionary; (obj: T | null | undefined): { [P in keyof T]: boolean }; } - type LodashMapValues6x1 = (obj: lodash.Dictionary | lodash.NumericDictionary | null | undefined) => lodash.Dictionary; - interface LodashMapValues7x1 { + type LodashMapValues5x1 = (obj: lodash.Dictionary | lodash.NumericDictionary | null | undefined) => lodash.Dictionary; + interface LodashMapValues6x1 { (obj: lodash.Dictionary | lodash.NumericDictionary | null | undefined): lodash.Dictionary; (obj: T | null | undefined): { [P in keyof T]: any }; } @@ -3536,20 +3504,15 @@ declare namespace _ { type LodashReduceRight3x5 = (accumulator: TResult) => TResult; type LodashReduceRight3x6 = (callback: lodash.MemoIteratorCappedRight) => TResult; interface LodashReject { - (predicate: (value: string) => boolean): LodashReject1x1; - (predicate: lodash.__, collection: string | null | undefined): LodashReject1x2; - (predicate: (value: string) => boolean, collection: string | null | undefined): string[]; - (predicate: lodash.ValueIterateeCustom): LodashReject2x1; - (predicate: lodash.__, collection: lodash.List | null | undefined): LodashReject2x2; + (predicate: lodash.ValueIterateeCustom): LodashReject1x1; + (predicate: lodash.__, collection: lodash.List | null | undefined): LodashReject1x2; (predicate: lodash.ValueIterateeCustom, collection: lodash.List | null | undefined): T[]; - (predicate: lodash.__, collection: T | null | undefined): LodashReject3x2; + (predicate: lodash.__, collection: T | null | undefined): LodashReject2x2; (predicate: lodash.ValueIterateeCustom, collection: T | null | undefined): Array; } - type LodashReject1x1 = (collection: string | null | undefined) => string[]; - type LodashReject1x2 = (predicate: (value: string) => boolean) => string[]; - type LodashReject2x1 = (collection: lodash.List | object | null | undefined) => T[]; - type LodashReject2x2 = (predicate: lodash.ValueIterateeCustom) => T[]; - type LodashReject3x2 = (predicate: lodash.ValueIterateeCustom) => Array; + type LodashReject1x1 = (collection: lodash.List | object | null | undefined) => T[]; + type LodashReject1x2 = (predicate: lodash.ValueIterateeCustom) => T[]; + type LodashReject2x2 = (predicate: lodash.ValueIterateeCustom) => Array; interface LodashRemove { (predicate: lodash.ValueIteratee): LodashRemove1x1; (predicate: lodash.__, array: lodash.List): LodashRemove1x2; diff --git a/types/lodash/lodash-tests.ts b/types/lodash/lodash-tests.ts index 1aa4bc3eb2..15feece064 100644 --- a/types/lodash/lodash-tests.ts +++ b/types/lodash/lodash-tests.ts @@ -1766,7 +1766,7 @@ _.chain([1, 2, 3, 4]).unshift(5, 6); // $ExpectType LoDashExplicitWrapper | null | undefined = anything; @@ -2338,7 +2338,7 @@ _.chain([1, 2, 3, 4]).unshift(5, 6); // $ExpectType LoDashExplicitWrapper }); - fp.forEach(stringIterator, ""); // $ExpectType string + fp.forEach(stringIterator, ""); // $ExpectType ArrayLike fp.forEach(valueIterator, array); // $ExpectType AbcObject[] fp.forEach(valueIterator)(array); // $ExpectType AbcObject[] fp.forEach(valueIterator, list); // $ExpectType ArrayLike diff --git a/types/lodash/scripts/generate-fp.ts b/types/lodash/scripts/generate-fp.ts index 817b485cf2..8dc4b7d3eb 100644 --- a/types/lodash/scripts/generate-fp.ts +++ b/types/lodash/scripts/generate-fp.ts @@ -153,6 +153,7 @@ async function processDefinitions(filePaths: string[], commonTypes: string[]): P for (const filePath of filePaths) { const definitions = await parseFile(filePath, commonTypes); for (const definition of definitions) { + definition.overloads = definition.overloads.filter(o => !o.params.some(p => p.includes('StringIterator'))); if (definition.overloads.every(o => o.params.length <= 1 && (o.returnType === "typeof _" || o.returnType === "LoDashStatic"))) { // Our convert technique doesn't work well on "typeof _" functions (or at least runInContext) // Plus, if there are 0-1 parameters, there's nothing to curry anyways.