Skip to content

Commit

Permalink
Closes gulpjs#10
Browse files Browse the repository at this point in the history
  • Loading branch information
gucong3000 committed Jan 23, 2018
1 parent 4dfcef3 commit 87d0b3e
Showing 2 changed files with 33 additions and 0 deletions.
7 changes: 7 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -19,6 +19,13 @@ declare namespace PluginError {
*/
new <E extends Error>(plugin: string, error: E, options?: Options): PluginError<E>;

/**
* @param plugin Plugin name
* @param error Base error / Error message
* @param options Error options
*/
new <E extends Error>(plugin: string, error: E | string, options?: Options): PluginError<E | {[K in keyof E]: undefined}>;

/**
* @param plugin Plugin name
* @param options Options with message
26 changes: 26 additions & 0 deletions test/types/test.ts
Original file line number Diff line number Diff line change
@@ -51,3 +51,29 @@ import PluginError = require("plugin-error");
}
}

{
const PLUGIN_NAME = 'test'

function createPluginError(err: Error | string) {
return new PluginError(PLUGIN_NAME, err);
}
}

{
// Inference with union type on second parameter
const PLUGIN_NAME = "test";

interface FooError extends Error {
foo: number;
}

function createPluginError(err: FooError | string) {
return new PluginError(PLUGIN_NAME, err);
}

const fooError: FooError = Object.assign(new Error("something broke"), {foo: 1});
const pluginError = createPluginError(fooError);
if (pluginError.foo !== undefined) {
const foo: number = pluginError.foo;
}
}

0 comments on commit 87d0b3e

Please sign in to comment.