mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-17 19:52:23 +08:00
Updated definition of VError to latet
This commit is contained in:
19
verror/index.d.ts
vendored
19
verror/index.d.ts
vendored
@@ -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[];
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user