Skip to content

Commit fc9396e

Browse files
authored
🤖 Merge PR DefinitelyTyped#73210 feat(async): remove depreciated exports, add missing async func exports by @hkleungai
1 parent 26f708a commit fc9396e

File tree

2 files changed

+208
-32
lines changed

2 files changed

+208
-32
lines changed

‎types/async/index.d.ts‎

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,13 @@ export function someLimit<T, E = Error>(
431431
arr: IterableCollection<T>,
432432
limit: number,
433433
iterator: AsyncBooleanIterator<T, E>,
434-
callback?: AsyncBooleanResultCallback<E>,
434+
callback: AsyncBooleanResultCallback<E>,
435435
): void;
436+
export function someLimit<T, E = Error>(
437+
arr: IterableCollection<T>,
438+
limit: number,
439+
iterator: AsyncBooleanIterator<T, E>,
440+
): Promise<boolean>;
436441
export const any: typeof some;
437442
export const anySeries: typeof someSeries;
438443
export const anyLimit: typeof someLimit;
@@ -576,16 +581,6 @@ export function doUntil<T, R, E = Error>(
576581
test: (/* ...results: T[], */ cb: AsyncBooleanResultCallback) => void,
577582
): Promise<R>;
578583

579-
export function during<E = Error>(
580-
test: (testCallback: AsyncBooleanResultCallback<E>) => void,
581-
fn: AsyncVoidFunction<E>,
582-
callback: ErrorCallback<E>,
583-
): void;
584-
export function doDuring<E = Error>(
585-
fn: AsyncVoidFunction<E>,
586-
test: (testCallback: AsyncBooleanResultCallback<E>) => void,
587-
callback: ErrorCallback<E>,
588-
): void;
589584
export function forever<E = Error>(next: (next: ErrorCallback<E>) => void, errBack: ErrorCallback<E>): void;
590585
export function waterfall<T>(tasks: Function[]): Promise<T>;
591586
export function waterfall<T, E = Error>(tasks: Function[], callback: AsyncResultCallback<T, E>): void;
@@ -615,7 +610,8 @@ export function auto<R extends Dictionary<any>, E = Error>(
615610
tasks: AsyncAutoTasks<R, E>,
616611
callback: AsyncResultCallback<R, E>,
617612
): void;
618-
export function autoInject<E = Error>(tasks: any, callback?: AsyncResultCallback<any, E>): void;
613+
export function autoInject<E = Error>(tasks: any, callback: AsyncResultCallback<any, E>): void;
614+
export function autoInject(tasks: any): Promise<any>;
619615

620616
export interface RetryOptions<E> {
621617
times?: number | undefined;
@@ -688,29 +684,46 @@ export function timesLimit<T, E = Error>(
688684
export function transform<T, R, E = Error>(
689685
arr: T[],
690686
iteratee: (acc: R[], item: T, key: number, callback: (error?: E) => void) => void,
691-
callback?: AsyncResultArrayCallback<T, E>,
687+
callback: AsyncResultArrayCallback<T, E>,
692688
): void;
689+
export function transform<T, R, E = Error>(
690+
arr: T[],
691+
iteratee: (acc: R[], item: T, key: number, callback: (error?: E) => void) => void,
692+
): Promise<Array<T | undefined>>;
693693
export function transform<T, R, E = Error>(
694694
arr: T[],
695695
acc: R[],
696696
iteratee: (acc: R[], item: T, key: number, callback: (error?: E) => void) => void,
697-
callback?: AsyncResultArrayCallback<T, E>,
697+
callback: AsyncResultArrayCallback<T, E>,
698698
): void;
699-
699+
export function transform<T, R, E = Error>(
700+
arr: T[],
701+
acc: R[],
702+
iteratee: (acc: R[], item: T, key: number, callback: (error?: E) => void) => void,
703+
): Promise<Array<T | undefined>>;
700704
export function transform<T, R, E = Error>(
701705
arr: { [key: string]: T },
702706
iteratee: (acc: { [key: string]: R }, item: T, key: string, callback: (error?: E) => void) => void,
703-
callback?: AsyncResultObjectCallback<T, E>,
707+
callback: AsyncResultObjectCallback<T, E>,
704708
): void;
705-
709+
export function transform<T, R, E = Error>(
710+
arr: { [key: string]: T },
711+
iteratee: (acc: { [key: string]: R }, item: T, key: string, callback: (error?: E) => void) => void,
712+
): Promise<Dictionary<T | undefined>>;
706713
export function transform<T, R, E = Error>(
707714
arr: { [key: string]: T },
708715
acc: { [key: string]: R },
709716
iteratee: (acc: { [key: string]: R }, item: T, key: string, callback: (error?: E) => void) => void,
710-
callback?: AsyncResultObjectCallback<T, E>,
717+
callback: AsyncResultObjectCallback<T, E>,
711718
): void;
719+
export function transform<T, R, E = Error>(
720+
arr: { [key: string]: T },
721+
acc: { [key: string]: R },
722+
iteratee: (acc: { [key: string]: R }, item: T, key: string, callback: (error?: E) => void) => void,
723+
): Promise<Dictionary<T | undefined>>;
712724

713725
export function race<T, E = Error>(tasks: Array<AsyncFunction<T, E>>, callback: AsyncResultCallback<T, E>): void;
726+
export function race<T, E = Error>(tasks: Array<AsyncFunction<T, E>>): Promise<T>;
714727

715728
export function tryEach<T, E = Error>(
716729
tasks: IterableCollection<AsyncFunction<T>>,

‎types/async/test/index.ts‎

Lines changed: 177 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,18 @@ promiseIterableString = async.sortBy(["file1", "file2", "file3"], (file, callbac
9696
});
9797

9898
async.some(["file1", "file2", "file3"], funcStringCbErrBoolean, (err: Error, result: boolean) => {});
99+
promiseBoolean = async.some(["file1", "file2", "file3"], funcStringCbErrBoolean);
99100
async.someLimit(["file1", "file2", "file3"], 2, funcStringCbErrBoolean, (err: Error, result: boolean) => {});
101+
promiseBoolean = async.someLimit(["file1", "file2", "file3"], 2, funcStringCbErrBoolean);
100102
async.any(["file1", "file2", "file3"], funcStringCbErrBoolean, (err: Error, result: boolean) => {});
103+
promiseBoolean = async.any(["file1", "file2", "file3"], funcStringCbErrBoolean);
101104

102105
async.every(["file1", "file2", "file3"], funcStringCbErrBoolean, (err: Error, result: boolean) => {});
103106
promiseBoolean = async.every(["file1", "file2", "file3"], funcStringCbErrBoolean);
104107
async.everyLimit(["file1", "file2", "file3"], 2, funcStringCbErrBoolean, (err: Error, result: boolean) => {});
105108
promiseBoolean = async.everyLimit(["file1", "file2", "file3"], 2, funcStringCbErrBoolean);
106109
async.all(["file1", "file2", "file3"], funcStringCbErrBoolean, (err: Error, result: boolean) => {});
110+
promiseBoolean = async.all(["file1", "file2", "file3"], funcStringCbErrBoolean);
107111

108112
async.concat(["dir1", "dir2", "dir3"], fs.readdir, (err, files) => {}); // $ExpectType void
109113
async.concat<fs.PathLike, string>(["dir1", "dir2", "dir3"], fs.readdir); // $ExpectType Promise<string[]>
@@ -259,20 +263,6 @@ async.until(whileTest, whileFn, (err: Error) => {});
259263
async.doWhilst(whileFn, whileTest, (err: Error) => {});
260264
async.doUntil(whileFn, whileTest, (err: Error) => {});
261265

262-
async.during(testCallback => {
263-
testCallback(new Error(), false);
264-
}, callback => {
265-
callback();
266-
}, error => {
267-
console.log(error);
268-
});
269-
async.doDuring(callback => {
270-
callback();
271-
}, testCallback => {
272-
testCallback(new Error(), false);
273-
}, error => {
274-
console.log(error);
275-
});
276266
async.forever(errBack => {
277267
errBack(new Error("Not going on forever."));
278268
}, error => {
@@ -1039,3 +1029,176 @@ const wrapped3 = async.timeout(myFunction3, 1000, { bar: "bar" });
10391029
wrapped3((err: Error, data: any) => {
10401030
console.log(`async.timeout 3 end ${data}`);
10411031
});
1032+
1033+
declare let autoInjectsTask: any;
1034+
// $ExpectType void
1035+
async.autoInject(autoInjectsTask, (error, result) => {
1036+
// $ExpectType Error | null | undefined
1037+
error;
1038+
// $ExpectType any
1039+
result;
1040+
});
1041+
// $ExpectType Promise<any>
1042+
async.autoInject(autoInjectsTask);
1043+
1044+
// $ExpectType void
1045+
async.transform<string, number>(
1046+
[] as string[],
1047+
(acc, item, key, callback) => {
1048+
// $ExpectType number[]
1049+
acc;
1050+
// $ExpectType string
1051+
item;
1052+
// $ExpectType number
1053+
key;
1054+
// $ExpectType (error?: Error | undefined) => void
1055+
callback;
1056+
},
1057+
(error, result) => {
1058+
// $ExpectType Error | null | undefined
1059+
error;
1060+
// $ExpectType (string | undefined)[] | undefined
1061+
result;
1062+
},
1063+
);
1064+
// $ExpectType Promise<(string | undefined)[]>
1065+
async.transform<string, number>(
1066+
[] as string[],
1067+
(acc, item, key, callback) => {
1068+
// $ExpectType number[]
1069+
acc;
1070+
// $ExpectType string
1071+
item;
1072+
// $ExpectType number
1073+
key;
1074+
// $ExpectType (error?: Error | undefined) => void
1075+
callback;
1076+
},
1077+
);
1078+
// $ExpectType void
1079+
async.transform<string, number>(
1080+
[] as string[],
1081+
[] as number[],
1082+
(acc, item, key, callback) => {
1083+
// $ExpectType number[]
1084+
acc;
1085+
// $ExpectType string
1086+
item;
1087+
// $ExpectType number
1088+
key;
1089+
// $ExpectType (error?: Error | undefined) => void
1090+
callback;
1091+
},
1092+
(error, result) => {
1093+
// $ExpectType Error | null | undefined
1094+
error;
1095+
// $ExpectType (string | undefined)[] | undefined
1096+
result;
1097+
},
1098+
);
1099+
// $ExpectType Promise<(string | undefined)[]>
1100+
async.transform<string, number>(
1101+
[] as string[],
1102+
[] as number[],
1103+
(acc, item, key, callback) => {
1104+
// $ExpectType number[]
1105+
acc;
1106+
// $ExpectType string
1107+
item;
1108+
// $ExpectType number
1109+
key;
1110+
// $ExpectType (error?: Error | undefined) => void
1111+
callback;
1112+
},
1113+
);
1114+
// $ExpectType void
1115+
async.transform<string, number>(
1116+
{ key: "value" },
1117+
(acc, item, key, callback) => {
1118+
// $ExpectType { [key: string]: number }
1119+
acc;
1120+
// $ExpectType string
1121+
item;
1122+
// $ExpectType string
1123+
key;
1124+
// $ExpectType (error?: Error | undefined) => void
1125+
callback;
1126+
},
1127+
(error, result) => {
1128+
// $ExpectType Error | undefined
1129+
error;
1130+
// $ExpectType Dictionary<string | undefined>
1131+
result;
1132+
},
1133+
);
1134+
// $ExpectType Promise<Dictionary<string | undefined>>
1135+
async.transform<string, number>(
1136+
{ key: "value" },
1137+
(acc, item, key, callback) => {
1138+
// $ExpectType { [key: string]: number }
1139+
acc;
1140+
// $ExpectType string
1141+
item;
1142+
// $ExpectType string
1143+
key;
1144+
// $ExpectType (error?: Error | undefined) => void
1145+
callback;
1146+
},
1147+
);
1148+
// $ExpectType void
1149+
async.transform<string, number>(
1150+
{ key: "value" },
1151+
{ key: 1 },
1152+
(acc, item, key, callback) => {
1153+
// $ExpectType { [key: string]: number }
1154+
acc;
1155+
// $ExpectType string
1156+
item;
1157+
// $ExpectType string
1158+
key;
1159+
// $ExpectType (error?: Error | undefined) => void
1160+
callback;
1161+
},
1162+
(error, result) => {
1163+
// $ExpectType Error | undefined
1164+
error;
1165+
// $ExpectType Dictionary<string | undefined>
1166+
result;
1167+
},
1168+
);
1169+
// $ExpectType Promise<Dictionary<string | undefined>>
1170+
async.transform<string, number>(
1171+
{ key: "value" },
1172+
{ key: 1 },
1173+
(acc, item, key, callback) => {
1174+
// $ExpectType { [key: string]: number }
1175+
acc;
1176+
// $ExpectType string
1177+
item;
1178+
// $ExpectType string
1179+
key;
1180+
// $ExpectType (error?: Error | undefined) => void
1181+
callback;
1182+
},
1183+
);
1184+
1185+
// $ExpectType void
1186+
async.race<string>(
1187+
[(taskCallback) => {
1188+
// $ExpectType (err?: Error | null | undefined, result?: string | undefined) => void
1189+
taskCallback;
1190+
}],
1191+
(error, result) => {
1192+
// $ExpectType Error | null | undefined
1193+
error;
1194+
// $ExpectType string | undefined
1195+
result;
1196+
},
1197+
);
1198+
// $ExpectType Promise<string>
1199+
async.race<string>(
1200+
[(taskCallback) => {
1201+
// $ExpectType (err?: Error | null | undefined, result?: string | undefined) => void
1202+
taskCallback;
1203+
}],
1204+
);

0 commit comments

Comments
 (0)