From 6325442ec9055c14715742ba5178006d8d392796 Mon Sep 17 00:00:00 2001 From: Jeremy Hon Date: Fri, 9 Mar 2018 23:59:04 +0800 Subject: [PATCH] replace overloaded array and dictionary params with union collection --- types/async/index.d.ts | 60 +++++++++++++----------------------------- 1 file changed, 19 insertions(+), 41 deletions(-) diff --git a/types/async/index.d.ts b/types/async/index.d.ts index 17fecb467b..e2ecb522bc 100644 --- a/types/async/index.d.ts +++ b/types/async/index.d.ts @@ -7,6 +7,7 @@ export as namespace async; export interface Dictionary { [key: string]: T; } +export type IterableCollection = T[] | IterableIterator | Dictionary export interface ErrorCallback { (err?: T): void; } export interface AsyncBooleanResultCallback { (err?: E, truthValue?: boolean): void; } @@ -36,11 +37,9 @@ export interface AsyncQueue { running(): number; idle(): boolean; concurrency: number; - push(task: T, callback?: ErrorCallback): void; + push(task: T | T[], callback?: ErrorCallback): void; push(task: T, callback?: AsyncResultCallback): void; - push(task: T[], callback?: ErrorCallback): void; - unshift(task: T, callback?: ErrorCallback): void; - unshift(task: T[], callback?: ErrorCallback): void; + unshift(task: T | T[], callback?: ErrorCallback): void; saturated: () => any; empty: () => any; drain: () => any; @@ -62,8 +61,7 @@ export interface AsyncPriorityQueue { concurrency: number; started: boolean; paused: boolean; - push(task: T, priority: number, callback?: AsyncResultArrayCallback): void; - push(task: T[], priority: number, callback?: AsyncResultArrayCallback): void; + push(task: T | T[], priority: number, callback?: AsyncResultArrayCallback): void; saturated: () => any; empty: () => any; drain: () => any; @@ -86,7 +84,6 @@ export interface AsyncCargo { length(): number; payload?: number; push(task: any, callback? : Function): void; - push(task: any[], callback? : Function): void; saturated(): void; empty(): void; drain(): void; @@ -97,39 +94,28 @@ export interface AsyncCargo { } // Collections -export function each(arr: T[] | IterableIterator, iterator: AsyncIterator, callback?: ErrorCallback): void; -export function each(arr: Dictionary, iterator: AsyncIterator, callback?: ErrorCallback): void; +export function each(arr: IterableCollection, iterator: AsyncIterator, callback?: ErrorCallback): void; export const eachSeries: typeof each; -export function eachLimit(arr: T[] | IterableIterator, limit: number, iterator: AsyncIterator, callback?: ErrorCallback): void; -export function eachLimit(arr: Dictionary, limit: number, iterator: AsyncIterator, callback?: ErrorCallback): void; +export function eachLimit(arr: IterableCollection, limit: number, iterator: AsyncIterator, callback?: ErrorCallback): void; export const forEach: typeof each; export const forEachSeries: typeof each; export const forEachLimit: typeof eachLimit; -export function forEachOf(obj: T[] | IterableIterator, iterator: AsyncForEachOfIterator, callback?: ErrorCallback): void; -export function forEachOf(obj: Dictionary, iterator: AsyncForEachOfIterator, callback?: ErrorCallback): void; +export function forEachOf(obj: IterableCollection, iterator: AsyncForEachOfIterator, callback?: ErrorCallback): void; export const forEachOfSeries: typeof forEachOf; -export function forEachOfLimit(obj: T[] | IterableIterator, limit: number, iterator: AsyncForEachOfIterator, callback?: ErrorCallback): void; -export function forEachOfLimit(obj: Dictionary, limit: number, iterator: AsyncForEachOfIterator, callback?: ErrorCallback): void; +export function forEachOfLimit(obj: IterableCollection, limit: number, iterator: AsyncForEachOfIterator, callback?: ErrorCallback): void; export const eachOf: typeof forEachOf; export const eachOfSeries: typeof forEachOf; export const eachOfLimit: typeof forEachOfLimit; export function map(arr: T[] | IterableIterator, iterator: AsyncResultIterator, callback?: AsyncResultArrayCallback): void; export function map(arr: Dictionary, iterator: AsyncResultIterator, callback?: AsyncResultArrayCallback): void; export const mapSeries: typeof map; -export function mapLimit( - arr: T[] | Dictionary | IterableIterator, - limit: number, - iterator: AsyncResultIterator, - callback?: AsyncResultArrayCallback -): void; +export function mapLimit(arr: IterableCollection, limit: number, iterator: AsyncResultIterator, callback?: AsyncResultArrayCallback): void; export function mapValuesLimit(obj: Dictionary, limit: number, iteratee: (value: T, key: string, callback: AsyncResultCallback) => void, callback: AsyncResultObjectCallback): void; export function mapValues(obj: Dictionary, iteratee: (value: T, key: string, callback: AsyncResultCallback) => void, callback: AsyncResultObjectCallback): void; export const mapValuesSeries: typeof mapValues; -export function filter(arr: T[] | IterableIterator, iterator: AsyncBooleanIterator, callback?: AsyncResultArrayCallback): void; -export function filter(arr: Dictionary, iterator: AsyncBooleanIterator, callback?: AsyncResultArrayCallback): void; +export function filter(arr: IterableCollection, iterator: AsyncBooleanIterator, callback?: AsyncResultArrayCallback): void; export const filterSeries: typeof filter; -export function filterLimit(arr: T[] | IterableIterator, limit: number, iterator: AsyncBooleanIterator, callback?: AsyncResultArrayCallback): void; -export function filterLimit(arr: Dictionary, limit: number, iterator: AsyncBooleanIterator, callback?: AsyncResultArrayCallback): void; +export function filterLimit(arr: IterableCollection, limit: number, iterator: AsyncBooleanIterator, callback?: AsyncResultArrayCallback): void; export const select: typeof filter; export const selectSeries: typeof filter; export const selectLimit: typeof filterLimit; @@ -141,36 +127,28 @@ export const inject: typeof reduce; export const foldl: typeof reduce; export const reduceRight: typeof reduce; export const foldr: typeof reduce; -export function detect(arr: T[] | IterableIterator, iterator: AsyncBooleanIterator, callback?: AsyncResultCallback): void; -export function detect(arr: Dictionary, iterator: AsyncBooleanIterator, callback?: AsyncResultCallback): void; +export function detect(arr: IterableCollection, iterator: AsyncBooleanIterator, callback?: AsyncResultCallback): void; export const detectSeries: typeof detect; -export function detectLimit(arr: T[] | IterableIterator, limit: number, iterator: AsyncBooleanIterator, callback?: AsyncResultCallback): void; -export function detectLimit(arr: Dictionary, limit: number, iterator: AsyncBooleanIterator, callback?: AsyncResultCallback): void; +export function detectLimit(arr: IterableCollection, limit: number, iterator: AsyncBooleanIterator, callback?: AsyncResultCallback): void; export const find: typeof detect; export const findSeries: typeof detect; export const findLimit: typeof detectLimit; export function sortBy(arr: T[] | IterableIterator, iterator: AsyncResultIterator, callback?: AsyncResultArrayCallback): void; -export function some(arr: T[] | IterableIterator, iterator: AsyncBooleanIterator, callback?: AsyncBooleanResultCallback): void; -export function some(arr: Dictionary, iterator: AsyncBooleanIterator, callback?: AsyncBooleanResultCallback): void; +export function some(arr: IterableCollection, iterator: AsyncBooleanIterator, callback?: AsyncBooleanResultCallback): void; export const someSeries: typeof some; -export function someLimit(arr: T[] | IterableIterator, limit: number, iterator: AsyncBooleanIterator, callback?: AsyncBooleanResultCallback): void; -export function someLimit(arr: Dictionary, limit: number, iterator: AsyncBooleanIterator, callback?: AsyncBooleanResultCallback): void; +export function someLimit(arr: IterableCollection, limit: number, iterator: AsyncBooleanIterator, callback?: AsyncBooleanResultCallback): void; export const any: typeof some; export const anySeries: typeof someSeries; export const anyLimit: typeof someLimit; -export function every(arr: T[] | IterableIterator, iterator: AsyncBooleanIterator, callback?: AsyncBooleanResultCallback): void; -export function every(arr: Dictionary, iterator: AsyncBooleanIterator, callback?: AsyncBooleanResultCallback): void; +export function every(arr: IterableCollection, iterator: AsyncBooleanIterator, callback?: AsyncBooleanResultCallback): void; export const everySeries: typeof every; -export function everyLimit(arr: T[] | IterableIterator, limit: number, iterator: AsyncBooleanIterator, callback?: AsyncBooleanResultCallback): void; -export function everyLimit(arr: Dictionary, limit: number, iterator: AsyncBooleanIterator, callback?: AsyncBooleanResultCallback): void; +export function everyLimit(arr: IterableCollection, limit: number, iterator: AsyncBooleanIterator, callback?: AsyncBooleanResultCallback): void; export const all: typeof every; export const allSeries: typeof every; export const allLimit: typeof everyLimit; -export function concat(arr: T[] | IterableIterator, iterator: AsyncResultIterator, callback?: AsyncResultArrayCallback): void; -export function concat(arr: Dictionary, iterator: AsyncResultIterator, callback?: AsyncResultArrayCallback): void; -export function concatLimit(arr: T[] | IterableIterator, limit: number, iterator: AsyncResultIterator, callback?: AsyncResultArrayCallback): void; -export function concatLimit(arr: Dictionary, limit: number,iterator: AsyncResultIterator, callback?: AsyncResultArrayCallback): void; +export function concat(arr: IterableCollection, iterator: AsyncResultIterator, callback?: AsyncResultArrayCallback): void; +export function concatLimit(arr: IterableCollection, limit: number, iterator: AsyncResultIterator, callback?: AsyncResultArrayCallback): void; export const concatSeries: typeof concat; // Control Flow