UNPKG

1.07 kBTypeScriptView Raw
1type nodeCallback<T> = (err: Error | null, ...a: T[]) => any;
2
3// Delegates to `succ` on sucecss or to `fail` on error
4// ex: Thing.load(123, iferr(cb, thing => ...))
5declare function iferr<T>(fail: (err: Error) => void, succ: (...result: T[]) => void): nodeCallback<T>;
6
7declare namespace iferr {
8 // Delegates to `succ` on sucecss or to `fail` on error
9 // ex: Thing.load(123, iferr(cb, thing => ...))
10 function iferr<T>(fail: (err: Error) => void, succ: (...result: T[]) => void): nodeCallback<T>;
11
12 // Like iferr, but also catches errors thrown from `succ` and passes to `fail`
13 function tiferr<T>(fail: (err: Error) => void, succ: (...result: T[]) => void): nodeCallback<T>;
14
15 // Delegate to the success function on success, throws the error otherwise
16 // ex: Thing.load(123, throwerr(thing => ...))
17 function throwerr<T>(succ: (...result: T[]) => void): nodeCallback<T>;
18
19 // Prints errors when one is passed, or does nothing otherwise
20 // ex: Thing.load(123, printerr)
21 function printerr(): nodeCallback<any>;
22}
23
24export = iferr;