Merge pull request #25934 from segayuu/fix-types-iferr

[@types/iferr] When err is undefined, fail is not executed
This commit is contained in:
Benjamin Lichtman
2018-05-31 10:09:51 -07:00
committed by GitHub
2 changed files with 4 additions and 4 deletions

View File

@@ -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;

View File

@@ -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 => ...))