Attempt filtering out StringIterator.

This commit is contained in:
Max Bogue
2019-01-09 10:34:27 -06:00
parent 08319af8f7
commit 9c21b9040c
4 changed files with 54 additions and 90 deletions
+1 -1
View File
@@ -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<boolean>
): string[];
+50 -87
View File
@@ -616,20 +616,15 @@ declare namespace _ {
<T>(iteratee: (value: T) => any): LodashForEach1x1<T>;
<T>(iteratee: lodash.__, collection: ReadonlyArray<T>): LodashForEach1x2<T>;
<T>(iteratee: (value: T) => any, collection: ReadonlyArray<T>): T[];
(iteratee: (value: string) => any): LodashForEach2x1;
(iteratee: lodash.__, collection: string): LodashForEach2x2;
(iteratee: (value: string) => any, collection: string): string;
<T>(iteratee: lodash.__, collection: lodash.List<T>): LodashForEach3x2<T>;
<T>(iteratee: lodash.__, collection: lodash.List<T>): LodashForEach2x2<T>;
<T>(iteratee: (value: T) => any, collection: lodash.List<T>): lodash.List<T>;
<T extends object>(iteratee: lodash.__, collection: T): LodashForEach4x2<T>;
<T extends object>(iteratee: lodash.__, collection: T): LodashForEach3x2<T>;
<T extends object>(iteratee: (value: T[keyof T]) => any, collection: T): T;
<T, TArray extends T[] | null | undefined>(iteratee: lodash.__, collection: TArray & (T[] | null | undefined)): LodashForEach5x2<T, TArray>;
<T, TArray extends T[] | null | undefined>(iteratee: lodash.__, collection: TArray & (T[] | null | undefined)): LodashForEach4x2<T, TArray>;
<T, TArray extends T[] | null | undefined>(iteratee: (value: T) => any, collection: TArray & (T[] | null | undefined)): TArray;
<TString extends string | null | undefined>(iteratee: lodash.__, collection: TString): LodashForEach6x2<TString>;
<TString extends string | null | undefined>(iteratee: (value: string) => any, collection: TString): TString;
<T, TList extends lodash.List<T> | null | undefined>(iteratee: lodash.__, collection: TList & (lodash.List<T> | null | undefined)): LodashForEach7x2<T, TList>;
<T, TList extends lodash.List<T> | null | undefined>(iteratee: lodash.__, collection: TList & (lodash.List<T> | null | undefined)): LodashForEach5x2<T, TList>;
<T, TList extends lodash.List<T> | null | undefined>(iteratee: (value: T) => any, collection: TList & (lodash.List<T> | null | undefined)): TList;
<T extends object>(iteratee: lodash.__, collection: T | null | undefined): LodashForEach8x2<T>;
<T extends object>(iteratee: lodash.__, collection: T | null | undefined): LodashForEach6x2<T>;
<T extends object>(iteratee: (value: T[keyof T]) => any, collection: T | null | undefined): T | null | undefined;
}
interface LodashForEach1x1<T> {
@@ -641,35 +636,24 @@ declare namespace _ {
<T1 extends object>(collection: T1 | null | undefined): T1 | null | undefined;
}
type LodashForEach1x2<T> = (iteratee: (value: T) => any) => T[];
interface LodashForEach2x1 {
(collection: string): string;
<TString extends string | null | undefined>(collection: TString): TString;
}
type LodashForEach2x2 = (iteratee: (value: string) => any) => string;
type LodashForEach3x2<T> = (iteratee: (value: T) => any) => lodash.List<T>;
type LodashForEach4x2<T> = (iteratee: (value: T[keyof T]) => any) => T;
type LodashForEach5x2<T, TArray> = (iteratee: (value: T) => any) => TArray;
type LodashForEach6x2<TString> = (iteratee: (value: string) => any) => TString;
type LodashForEach7x2<T, TList> = (iteratee: (value: T) => any) => TList;
type LodashForEach8x2<T> = (iteratee: (value: T[keyof T]) => any) => T | null | undefined;
type LodashForEach2x2<T> = (iteratee: (value: T) => any) => lodash.List<T>;
type LodashForEach3x2<T> = (iteratee: (value: T[keyof T]) => any) => T;
type LodashForEach4x2<T, TArray> = (iteratee: (value: T) => any) => TArray;
type LodashForEach5x2<T, TList> = (iteratee: (value: T) => any) => TList;
type LodashForEach6x2<T> = (iteratee: (value: T[keyof T]) => any) => T | null | undefined;
interface LodashForEachRight {
<T>(iteratee: (value: T) => any): LodashForEachRight1x1<T>;
<T>(iteratee: lodash.__, collection: ReadonlyArray<T>): LodashForEachRight1x2<T>;
<T>(iteratee: (value: T) => any, collection: ReadonlyArray<T>): T[];
(iteratee: (value: string) => any): LodashForEachRight2x1;
(iteratee: lodash.__, collection: string): LodashForEachRight2x2;
(iteratee: (value: string) => any, collection: string): string;
<T>(iteratee: lodash.__, collection: lodash.List<T>): LodashForEachRight3x2<T>;
<T>(iteratee: lodash.__, collection: lodash.List<T>): LodashForEachRight2x2<T>;
<T>(iteratee: (value: T) => any, collection: lodash.List<T>): lodash.List<T>;
<T extends object>(iteratee: lodash.__, collection: T): LodashForEachRight4x2<T>;
<T extends object>(iteratee: lodash.__, collection: T): LodashForEachRight3x2<T>;
<T extends object>(iteratee: (value: T[keyof T]) => any, collection: T): T;
<T, TArray extends T[] | null | undefined>(iteratee: lodash.__, collection: TArray & (T[] | null | undefined)): LodashForEachRight5x2<T, TArray>;
<T, TArray extends T[] | null | undefined>(iteratee: lodash.__, collection: TArray & (T[] | null | undefined)): LodashForEachRight4x2<T, TArray>;
<T, TArray extends T[] | null | undefined>(iteratee: (value: T) => any, collection: TArray & (T[] | null | undefined)): TArray;
<TString extends string | null | undefined>(iteratee: lodash.__, collection: TString): LodashForEachRight6x2<TString>;
<TString extends string | null | undefined>(iteratee: (value: string) => any, collection: TString): TString;
<T, TList extends lodash.List<T> | null | undefined>(iteratee: lodash.__, collection: TList & (lodash.List<T> | null | undefined)): LodashForEachRight7x2<T, TList>;
<T, TList extends lodash.List<T> | null | undefined>(iteratee: lodash.__, collection: TList & (lodash.List<T> | null | undefined)): LodashForEachRight5x2<T, TList>;
<T, TList extends lodash.List<T> | null | undefined>(iteratee: (value: T) => any, collection: TList & (lodash.List<T> | null | undefined)): TList;
<T extends object>(iteratee: lodash.__, collection: T | null | undefined): LodashForEachRight8x2<T>;
<T extends object>(iteratee: lodash.__, collection: T | null | undefined): LodashForEachRight6x2<T>;
<T extends object>(iteratee: (value: T[keyof T]) => any, collection: T | null | undefined): T | null | undefined;
}
interface LodashForEachRight1x1<T> {
@@ -681,17 +665,11 @@ declare namespace _ {
<T1 extends object>(collection: T1 | null | undefined): T1 | null | undefined;
}
type LodashForEachRight1x2<T> = (iteratee: (value: T) => any) => T[];
interface LodashForEachRight2x1 {
(collection: string): string;
<TString extends string | null | undefined>(collection: TString): TString;
}
type LodashForEachRight2x2 = (iteratee: (value: string) => any) => string;
type LodashForEachRight3x2<T> = (iteratee: (value: T) => any) => lodash.List<T>;
type LodashForEachRight4x2<T> = (iteratee: (value: T[keyof T]) => any) => T;
type LodashForEachRight5x2<T, TArray> = (iteratee: (value: T) => any) => TArray;
type LodashForEachRight6x2<TString> = (iteratee: (value: string) => any) => TString;
type LodashForEachRight7x2<T, TList> = (iteratee: (value: T) => any) => TList;
type LodashForEachRight8x2<T> = (iteratee: (value: T[keyof T]) => any) => T | null | undefined;
type LodashForEachRight2x2<T> = (iteratee: (value: T) => any) => lodash.List<T>;
type LodashForEachRight3x2<T> = (iteratee: (value: T[keyof T]) => any) => T;
type LodashForEachRight4x2<T, TArray> = (iteratee: (value: T) => any) => TArray;
type LodashForEachRight5x2<T, TList> = (iteratee: (value: T) => any) => TList;
type LodashForEachRight6x2<T> = (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<T, U> = (end: number) => lodash.List<T | U>;
type LodashFill2x14<T, U> = (start: number) => lodash.List<T | U>;
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[];
<T, S extends T>(predicate: lodash.ValueIteratorTypeGuard<T, S>): LodashFilter2x1<T, S>;
<T>(predicate: lodash.__, collection: lodash.List<T> | null | undefined): LodashFilter2x2<T>;
<T, S extends T>(predicate: lodash.ValueIteratorTypeGuard<T, S>): LodashFilter1x1<T, S>;
<T>(predicate: lodash.__, collection: lodash.List<T> | null | undefined): LodashFilter1x2<T>;
<T, S extends T>(predicate: lodash.ValueIteratorTypeGuard<T, S>, collection: lodash.List<T> | null | undefined): S[];
<T>(predicate: lodash.ValueIterateeCustom<T, boolean>): LodashFilter3x1<T>;
<T>(predicate: lodash.ValueIterateeCustom<T, boolean>): LodashFilter2x1<T>;
<T>(predicate: lodash.ValueIterateeCustom<T, boolean>, collection: lodash.List<T> | null | undefined): T[];
<T extends object, S extends T[keyof T]>(predicate: lodash.ValueIteratorTypeGuard<T[keyof T], S>): LodashFilter4x1<T, S>;
<T extends object>(predicate: lodash.__, collection: T | null | undefined): LodashFilter4x2<T>;
<T extends object, S extends T[keyof T]>(predicate: lodash.ValueIteratorTypeGuard<T[keyof T], S>): LodashFilter3x1<T, S>;
<T extends object>(predicate: lodash.__, collection: T | null | undefined): LodashFilter3x2<T>;
<T extends object, S extends T[keyof T]>(predicate: lodash.ValueIteratorTypeGuard<T[keyof T], S>, collection: T | null | undefined): S[];
<T extends object>(predicate: lodash.ValueIterateeCustom<T[keyof T], boolean>, collection: T | null | undefined): Array<T[keyof T]>;
}
type LodashFilter1x1 = (collection: string | string[] | null | undefined) => string[];
type LodashFilter1x2 = (predicate: (value: string) => boolean) => string[];
type LodashFilter2x1<T, S> = (collection: lodash.List<T> | null | undefined) => S[];
interface LodashFilter2x2<T> {
type LodashFilter1x1<T, S> = (collection: lodash.List<T> | null | undefined) => S[];
interface LodashFilter1x2<T> {
<S extends T>(predicate: lodash.ValueIteratorTypeGuard<T, S>): S[];
(predicate: lodash.ValueIterateeCustom<T, boolean>): T[];
}
type LodashFilter3x1<T> = (collection: lodash.List<T> | object | null | undefined) => T[];
type LodashFilter4x1<T, S> = (collection: T | null | undefined) => S[];
interface LodashFilter4x2<T> {
type LodashFilter2x1<T> = (collection: lodash.List<T> | object | null | undefined) => T[];
type LodashFilter3x1<T, S> = (collection: T | null | undefined) => S[];
interface LodashFilter3x2<T> {
<S extends T[keyof T]>(predicate: lodash.ValueIteratorTypeGuard<T[keyof T], S>): S[];
(predicate: lodash.ValueIterateeCustom<T[keyof T], boolean>): Array<T[keyof T]>;
}
@@ -2131,45 +2104,40 @@ declare namespace _ {
type LodashMapKeys2x1 = <T extends object>(object: T | null | undefined) => lodash.Dictionary<T[keyof T]>;
type LodashMapKeys2x2<T> = (iteratee: lodash.ValueIteratee<string>) => lodash.Dictionary<T[keyof T]>;
interface LodashMapValues {
<TResult>(callback: (value: string) => TResult): LodashMapValues1x1<TResult>;
(callback: lodash.__, obj: string | null | undefined): LodashMapValues1x2;
<TResult>(callback: (value: string) => TResult, obj: string | null | undefined): lodash.NumericDictionary<TResult>;
<T, TResult>(callback: (value: T) => TResult): LodashMapValues2x1<T, TResult>;
<T>(callbackOrIterateeOrIterateeOrIteratee: lodash.__, obj: lodash.Dictionary<T> | lodash.NumericDictionary<T> | null | undefined): LodashMapValues2x2<T>;
<T, TResult>(callback: (value: T) => TResult): LodashMapValues1x1<T, TResult>;
<T>(callbackOrIterateeOrIterateeOrIteratee: lodash.__, obj: lodash.Dictionary<T> | lodash.NumericDictionary<T> | null | undefined): LodashMapValues1x2<T>;
<T, TResult>(callback: (value: T) => TResult, obj: lodash.Dictionary<T> | lodash.NumericDictionary<T> | null | undefined): lodash.Dictionary<TResult>;
<T extends object, TResult>(callback: (value: T[keyof T]) => TResult): LodashMapValues3x1<T, TResult>;
<T extends object>(callbackOrIterateeOrIteratee: lodash.__, obj: T | null | undefined): LodashMapValues3x2<T>;
<T extends object, TResult>(callback: (value: T[keyof T]) => TResult): LodashMapValues2x1<T, TResult>;
<T extends object>(callbackOrIterateeOrIteratee: lodash.__, obj: T | null | undefined): LodashMapValues2x2<T>;
<T extends object, TResult>(callback: (value: T[keyof T]) => TResult, obj: T | null | undefined): { [P in keyof T]: TResult };
(iteratee: object): LodashMapValues4x1;
(iteratee: object): LodashMapValues3x1;
<T>(iteratee: object, obj: lodash.Dictionary<T> | lodash.NumericDictionary<T> | null | undefined): lodash.Dictionary<boolean>;
<T extends object>(iteratee: object, obj: T | null | undefined): { [P in keyof T]: boolean };
<T, TKey extends keyof T>(iteratee: TKey): LodashMapValues6x1<T, TKey>;
<T, TKey extends keyof T>(iteratee: TKey): LodashMapValues5x1<T, TKey>;
<T, TKey extends keyof T>(iteratee: TKey, obj: lodash.Dictionary<T> | lodash.NumericDictionary<T> | null | undefined): lodash.Dictionary<T[TKey]>;
(iteratee: string): LodashMapValues7x1;
(iteratee: string): LodashMapValues6x1;
<T>(iteratee: string, obj: lodash.Dictionary<T> | lodash.NumericDictionary<T> | null | undefined): lodash.Dictionary<any>;
<T extends object>(iteratee: string, obj: T | null | undefined): { [P in keyof T]: any };
}
type LodashMapValues1x1<TResult> = (obj: string | null | undefined) => lodash.NumericDictionary<TResult>;
type LodashMapValues1x2 = <TResult>(callback: (value: string) => TResult) => lodash.NumericDictionary<TResult>;
type LodashMapValues2x1<T, TResult> = (obj: lodash.Dictionary<T> | lodash.NumericDictionary<T> | null | undefined) => lodash.Dictionary<TResult>;
interface LodashMapValues2x2<T> {
type LodashMapValues1x1<T, TResult> = (obj: lodash.Dictionary<T> | lodash.NumericDictionary<T> | null | undefined) => lodash.Dictionary<TResult>;
interface LodashMapValues1x2<T> {
<TResult>(callback: (value: T) => TResult): lodash.Dictionary<TResult>;
(iteratee: object): lodash.Dictionary<boolean>;
<TKey extends keyof T>(iteratee: TKey): lodash.Dictionary<T[TKey]>;
(iteratee: string): lodash.Dictionary<any>;
}
type LodashMapValues3x1<T, TResult> = (obj: T | null | undefined) => { [P in keyof T]: TResult };
interface LodashMapValues3x2<T> {
type LodashMapValues2x1<T, TResult> = (obj: T | null | undefined) => { [P in keyof T]: TResult };
interface LodashMapValues2x2<T> {
<TResult>(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 {
<T>(obj: lodash.Dictionary<T> | lodash.NumericDictionary<T> | null | undefined): lodash.Dictionary<boolean>;
<T extends object>(obj: T | null | undefined): { [P in keyof T]: boolean };
}
type LodashMapValues6x1<T, TKey extends keyof T> = (obj: lodash.Dictionary<T> | lodash.NumericDictionary<T> | null | undefined) => lodash.Dictionary<T[TKey]>;
interface LodashMapValues7x1 {
type LodashMapValues5x1<T, TKey extends keyof T> = (obj: lodash.Dictionary<T> | lodash.NumericDictionary<T> | null | undefined) => lodash.Dictionary<T[TKey]>;
interface LodashMapValues6x1 {
<T>(obj: lodash.Dictionary<T> | lodash.NumericDictionary<T> | null | undefined): lodash.Dictionary<any>;
<T extends object>(obj: T | null | undefined): { [P in keyof T]: any };
}
@@ -3536,20 +3504,15 @@ declare namespace _ {
type LodashReduceRight3x5<TResult> = (accumulator: TResult) => TResult;
type LodashReduceRight3x6<T, TResult> = (callback: lodash.MemoIteratorCappedRight<T[keyof T], TResult>) => TResult;
interface LodashReject {
(predicate: (value: string) => boolean): LodashReject1x1;
(predicate: lodash.__, collection: string | null | undefined): LodashReject1x2;
(predicate: (value: string) => boolean, collection: string | null | undefined): string[];
<T>(predicate: lodash.ValueIterateeCustom<T, boolean>): LodashReject2x1<T>;
<T>(predicate: lodash.__, collection: lodash.List<T> | null | undefined): LodashReject2x2<T>;
<T>(predicate: lodash.ValueIterateeCustom<T, boolean>): LodashReject1x1<T>;
<T>(predicate: lodash.__, collection: lodash.List<T> | null | undefined): LodashReject1x2<T>;
<T>(predicate: lodash.ValueIterateeCustom<T, boolean>, collection: lodash.List<T> | null | undefined): T[];
<T extends object>(predicate: lodash.__, collection: T | null | undefined): LodashReject3x2<T>;
<T extends object>(predicate: lodash.__, collection: T | null | undefined): LodashReject2x2<T>;
<T extends object>(predicate: lodash.ValueIterateeCustom<T[keyof T], boolean>, collection: T | null | undefined): Array<T[keyof T]>;
}
type LodashReject1x1 = (collection: string | null | undefined) => string[];
type LodashReject1x2 = (predicate: (value: string) => boolean) => string[];
type LodashReject2x1<T> = (collection: lodash.List<T> | object | null | undefined) => T[];
type LodashReject2x2<T> = (predicate: lodash.ValueIterateeCustom<T, boolean>) => T[];
type LodashReject3x2<T> = (predicate: lodash.ValueIterateeCustom<T[keyof T], boolean>) => Array<T[keyof T]>;
type LodashReject1x1<T> = (collection: lodash.List<T> | object | null | undefined) => T[];
type LodashReject1x2<T> = (predicate: lodash.ValueIterateeCustom<T, boolean>) => T[];
type LodashReject2x2<T> = (predicate: lodash.ValueIterateeCustom<T[keyof T], boolean>) => Array<T[keyof T]>;
interface LodashRemove {
<T>(predicate: lodash.ValueIteratee<T>): LodashRemove1x1<T>;
<T>(predicate: lodash.__, array: lodash.List<T>): LodashRemove1x2<T>;
+2 -2
View File
@@ -1766,7 +1766,7 @@ _.chain([1, 2, 3, 4]).unshift(5, 6); // $ExpectType LoDashExplicitWrapper<number
fp.filter("", dictionary); // $ExpectType AbcObject[]
fp.filter({ a: 42 }, dictionary); // $ExpectType AbcObject[]
fp.filter(["a", 42], dictionary); // $ExpectType AbcObject[]
fp.filter(Boolean)(["a", "b"]); // $ExpectType string[]
fp.filter(Boolean)(["a", "b"]); // $ExpectType any[]
// Test filtering with type guard
const a2: Array<string | number> | null | undefined = anything;
@@ -2338,7 +2338,7 @@ _.chain([1, 2, 3, 4]).unshift(5, 6); // $ExpectType LoDashExplicitWrapper<number
collection; // $ExpectType NumericDictionary<AbcObject>
});
fp.forEach(stringIterator, ""); // $ExpectType string
fp.forEach(stringIterator, ""); // $ExpectType ArrayLike<string>
fp.forEach(valueIterator, array); // $ExpectType AbcObject[]
fp.forEach(valueIterator)(array); // $ExpectType AbcObject[]
fp.forEach(valueIterator, list); // $ExpectType ArrayLike<AbcObject>
+1
View File
@@ -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.