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