Updated definition of VError to latet

This commit is contained in:
maghis
2016-11-21 18:25:11 -05:00
parent 8841dfc744
commit 50499e0430
2 changed files with 32 additions and 1 deletions

19
verror/index.d.ts vendored
View File

@@ -4,6 +4,15 @@
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
type VErrorInfo = { [key: string]: any };
declare interface VErrorOptions {
cause: Error;
name?: string;
strict?: boolean;
constructorOpt?: Function;
info?: VErrorInfo;
}
/*
* VError([cause], fmt[, arg...]): Like JavaScript's built-in Error class, but
@@ -24,7 +33,14 @@ declare class VError extends Error {
static SError: typeof SError;
static MultiError: typeof MultiError;
static WError: typeof WError;
cause(): Error;
static cause(err: Error): Error | null;
static info(err: Error): VErrorInfo;
static findCauseByName(err: Error, name: string): Error | null;
static fullStack(err: Error): string;
cause(): Error | undefined;
constructor(options: VErrorOptions, message: string, ...params: any[]);
constructor(cause: Error, message: string, ...params: any[]);
constructor(message: string, ...params: any[]);
}
@@ -46,6 +62,7 @@ declare class SError extends VError {
*/
declare class MultiError extends VError {
constructor(errors: Error[]);
errors(): Error[];
}
/*

View File

@@ -13,5 +13,19 @@ var serror = new VError.SError(error, "bar");
var multiError = new VError.MultiError([verror1, verror2]);
var werror = new VError.WError(verror1, "foobar");
var verror3 = new VError({
name: "fooError",
cause: error,
info: {
"info0": "baz"
}
}, "bar");
var cause1: Error = verror1.cause();
var cause2: Error = werror.cause();
const info: { [k: string]: any } = VError.info(verror3);
const namedCause: Error | null = VError.findCauseByName(verror3, "fooError");
const stack: string = VError.fullStack(verror3);
const cause3: Error | null = VError.cause(verror3);