mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-30 18:43:21 +08:00
Merge pull request #25934 from segayuu/fix-types-iferr
[@types/iferr] When err is undefined, fail is not executed
This commit is contained in:
@@ -7,7 +7,7 @@ const { tiferr, throwerr, printerr } = iferr;
|
||||
|
||||
const { readFile } = fs;
|
||||
|
||||
const errcb = (err: Error | undefined) => { throw err; };
|
||||
const errcb = (err: Error) => { throw err; };
|
||||
|
||||
readFile("test.txt", iferr(errcb, result => {
|
||||
Buffer.from("test", "utf8") === result;
|
||||
|
||||
6
types/iferr/index.d.ts
vendored
6
types/iferr/index.d.ts
vendored
@@ -7,15 +7,15 @@ type nodeCallback<T> = (err: Error | undefined, ...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 | undefined) => void, succ: (...result: T[]) => void): nodeCallback<T>;
|
||||
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 | undefined) => void, succ: (...result: T[]) => void): nodeCallback<T>;
|
||||
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 | undefined) => void, succ: (...result: T[]) => void): nodeCallback<T>;
|
||||
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 => ...))
|
||||
|
||||
Reference in New Issue
Block a user