File tree Expand file tree Collapse file tree 2 files changed +43
-9
lines changed Expand file tree Collapse file tree 2 files changed +43
-9
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments