diff --git a/verror/index.d.ts b/verror/index.d.ts index 2c88ddb8e8..7b827b653d 100644 --- a/verror/index.d.ts +++ b/verror/index.d.ts @@ -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[]; } /* diff --git a/verror/verror-tests.ts b/verror/verror-tests.ts index 1be9837645..0c386987c1 100644 --- a/verror/verror-tests.ts +++ b/verror/verror-tests.ts @@ -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); +