File: index.d.ts

package info (click to toggle)
node-iferr 1.0.2%2B~1.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 136 kB
  • sloc: javascript: 12; makefile: 2
file content (29 lines) | stat: -rw-r--r-- 1,271 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Type definitions for iferr 1.0
// Project: https://github.com/shesek/iferr
// Definitions by: segayuu <https://github.com/segayuu>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

type nodeCallback<T> = (err: Error | null, ...a: T[]) => any;

// Delegates to `succ` on sucecss or to `fail` on error
// ex: Thing.load(123, iferr(cb, thing => ...))
declare function iferr<T>(fail: (err: Error) => void, succ: (...result: T[]) => void): nodeCallback<T>;

declare namespace iferr {
    // Delegates to `succ` on sucecss or to `fail` on error
    // ex: Thing.load(123, iferr(cb, thing => ...))
    function iferr<T>(fail: (err: Error) => void, succ: (...result: T[]) => void): nodeCallback<T>;

    // Like iferr, but also catches errors thrown from `succ` and passes to `fail`
    function tiferr<T>(fail: (err: Error) => void, succ: (...result: T[]) => void): nodeCallback<T>;

    // Delegate to the success function on success, throws the error otherwise
    // ex: Thing.load(123, throwerr(thing => ...))
    function throwerr<T>(succ: (...result: T[]) => void): nodeCallback<T>;

    // Prints errors when one is passed, or does nothing otherwise
    // ex: Thing.load(123, printerr)
    function printerr(): nodeCallback<any>;
}

export = iferr;