Skip to content

Commit dc76155

Browse files
committed
Closes #10
1 parent 4dfcef3 commit dc76155

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed

index.d.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,10 @@ declare namespace PluginError {
77

88
/**
99
* @param plugin Plugin name
10-
* @param message Error message
10+
* @param error Base error / Error message
1111
* @param options Error options
1212
*/
13-
new (plugin: string, message: string, options?: Options): PluginError;
14-
15-
/**
16-
* @param plugin Plugin name
17-
* @param error Base error
18-
* @param options Error options
19-
*/
20-
new <E extends Error>(plugin: string, error: E, options?: Options): PluginError<E>;
13+
new <E extends Error>(plugin: string, error: E | string, options?: Options): PluginError<E>;
2114

2215
/**
2316
* @param plugin Plugin name

test/types/test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,44 @@ import PluginError = require("plugin-error");
5151
}
5252
}
5353

54+
{
55+
const PLUGIN_NAME = 'test';
56+
function createPluginError(err: Error | string) {
57+
return new PluginError(PLUGIN_NAME, err);
58+
}
59+
}
60+
61+
{
62+
const PLUGIN_NAME = 'test';
63+
64+
interface IFooError extends Error {
65+
foo: number;
66+
}
67+
68+
function createPluginError(err: IFooError | string) {
69+
return new PluginError(PLUGIN_NAME, err);
70+
}
71+
72+
const fooError: IFooError = Object.assign(new Error('something broke'), {foo: 1});
73+
const pluginError = createPluginError(fooError);
74+
const foo: number = pluginError.foo;
75+
}
76+
77+
{
78+
// Inference with union type on second parameter and dependent properties
79+
const PLUGIN_NAME = 'test';
80+
81+
interface IFooBarError extends Error {
82+
foo: number;
83+
bar: number;
84+
}
85+
86+
function createPluginError(err: IFooBarError | string) {
87+
return new PluginError(PLUGIN_NAME, err);
88+
}
89+
90+
const fooError: IFooBarError = Object.assign(new Error('something broke'), {foo: 1, bar: 2});
91+
const pluginError = createPluginError(fooError);
92+
const foo: number = pluginError.foo;
93+
const bar: number = pluginError.bar;
94+
}

0 commit comments

Comments
 (0)