diff --git a/verror/index.d.ts b/verror/index.d.ts index 96f711c9f7..63c68fd7f9 100644 --- a/verror/index.d.ts +++ b/verror/index.d.ts @@ -3,20 +3,6 @@ // Definitions by: Sven Reglitzki , Maxime Toumi-M // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -// tslint:disable-next-line:functional-interfaces -interface VErrorInfo { - [key: string]: any; -} - -declare interface VErrorOptions { - cause?: Error | null | undefined; - name?: string; - strict?: boolean; - constructorOpt?: (...args: any[]) => void; - info?: VErrorInfo; -} - /* * VError([cause], fmt[, arg...]): Like JavaScript's built-in Error class, but * supports a "cause" argument (another error) and a printf-style message. The @@ -33,47 +19,56 @@ declare interface VErrorOptions { */ declare class VError extends Error { static VError: typeof VError; - static SError: typeof SError; - static MultiError: typeof MultiError; - static WError: typeof WError; static cause(err: Error): Error | null; - static info(err: Error): VErrorInfo; + static info(err: Error): VError.Info; static findCauseByName(err: Error, name: string): Error | null; static fullStack(err: Error): string; cause(): Error | undefined; - constructor(options: VErrorOptions, message: string, ...params: any[]); + constructor(options: VError.Options, message: string, ...params: any[]); constructor(cause: Error, message: string, ...params: any[]); constructor(message: string, ...params: any[]); } -/* - * SError is like VError, but stricter about types. You cannot pass "null" or - * "undefined" as string arguments to the formatter. Since SError is only a - * different function, not really a different class, we don't set - * SError.prototype.name. - */ -declare class SError extends VError { -} +declare namespace VError { + interface Info { + [key: string]: any; + } -/* - * Represents a collection of errors for the purpose of consumers that generally - * only deal with one error. Callers can extract the individual errors - * contained in this object, but may also just treat it as a normal single - * error, in which case a summary message will be printed. - */ -declare class MultiError extends VError { - constructor(errors: Error[]); - errors(): Error[]; -} + interface Options { + cause?: Error | null | undefined; + name?: string; + strict?: boolean; + constructorOpt?: (...args: any[]) => void; + info?: Info; + } -/* - * Like JavaScript's built-in Error class, but supports a "cause" argument which - * is wrapped, not "folded in" as with VError. Accepts a printf-style message. - * The cause argument can be null. - */ -declare class WError extends VError { + /* + * SError is like VError, but stricter about types. You cannot pass "null" or + * "undefined" as string arguments to the formatter. Since SError is only a + * different function, not really a different class, we don't set + * SError.prototype.name. + */ + class SError extends VError {} + + /* + * Represents a collection of errors for the purpose of consumers that generally + * only deal with one error. Callers can extract the individual errors + * contained in this object, but may also just treat it as a normal single + * error, in which case a summary message will be printed. + */ + class MultiError extends VError { + constructor(errors: Error[]); + errors(): Error[]; + } + + /* + * Like JavaScript's built-in Error class, but supports a "cause" argument which + * is wrapped, not "folded in" as with VError. Accepts a printf-style message. + * The cause argument can be null. + */ + class WError extends VError {} } export = VError; diff --git a/verror/tslint.json b/verror/tslint.json new file mode 100644 index 0000000000..2221e40e4a --- /dev/null +++ b/verror/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" } \ No newline at end of file diff --git a/verror/verror-tests.ts b/verror/verror-tests.ts index de1838ee9b..8a243d2fab 100644 --- a/verror/verror-tests.ts +++ b/verror/verror-tests.ts @@ -1,17 +1,12 @@ -// Type definitions for verror v1.6.0 -// Project: https://github.com/davepacheco/node-verror -// Definitions by: Sven Reglitzki -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - - import VError = require("verror"); +import { VError as VError2, MultiError, SError, WError } from "verror"; var error = new Error("foo"); var verror1 = new VError(error, "bar"); -var verror2 = new VError.VError(error, "bar"); -var serror = new VError.SError(error, "bar"); -var multiError = new VError.MultiError([verror1, verror2]); -var werror = new VError.WError(verror1, "foobar"); +var verror2 = new VError2(error, "bar"); +var serror = new SError(error, "bar"); +var multiError = new MultiError([verror1, verror2]); +var werror = new WError(verror1, "foobar"); var verror3 = new VError({ name: "fooError",