diff --git a/types/plugin-error/index.d.ts b/types/plugin-error/index.d.ts new file mode 100644 index 0000000000..87aa892832 --- /dev/null +++ b/types/plugin-error/index.d.ts @@ -0,0 +1,58 @@ +// Type definitions for plugin-error 0.1 +// Project: https://github.com/jonschlinkert/plugin-error +// Definitions by: Rogier Schouten +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module 'plugin-error' { + namespace PluginError { + interface PluginErrorOpts { + /** + * By default the stack will not be shown. Set options.showStack to true if you think the stack is important for your error. + */ + showStack?: boolean; + /** + * Error properties will be included in err.toString(), but may be omitted by including {showProperties: false} in the options + */ + showProperties?: boolean; + } + + interface PluginErrorOpts2 extends PluginErrorOpts { + /** + * If you pass an error object as the message the stack will be pulled from that, otherwise one will be created. + */ + message?: string | Error; + } + + interface PluginErrorOpts3 extends PluginErrorOpts2 { + /** + * The name of the plugin + */ + plugin?: string; + } + } + + class PluginError extends Error { + /** + * Constructor + * @param pluginName + * @param message If you pass an error object as the message the stack will be pulled from that, otherwise one will be created. + * @param options + */ + constructor(pluginName: string, message: string | Error, options?: PluginError.PluginErrorOpts); + + /** + * Constructor + * @param pluginName + * @param options + */ + constructor(pluginName: string, options: PluginError.PluginErrorOpts2); + + /** + * Constructor + * @param options + */ + constructor(options: PluginError.PluginErrorOpts3); + } + + export = PluginError; +} diff --git a/types/plugin-error/plugin-error-tests.ts b/types/plugin-error/plugin-error-tests.ts new file mode 100644 index 0000000000..590e8db0fc --- /dev/null +++ b/types/plugin-error/plugin-error-tests.ts @@ -0,0 +1,23 @@ +import * as PluginError from 'plugin-error'; + +let e: PluginError; + +// string message +e = new PluginError('my-plugin', 'message'); +e = new PluginError('my-plugin', 'message', { showProperties: false, showStack: false }); +e = new PluginError('my-plugin', { showProperties: false, showStack: false, message: 'message' }); +e = new PluginError({ showProperties: false, showStack: false, message: 'message', plugin: 'my-plugin' }); + +// error instead of message +e = new PluginError('my-plugin', new Error('message')); +e = new PluginError('my-plugin', new Error('message'), { showProperties: false, showStack: false }); +e = new PluginError('my-plugin', { showProperties: false, showStack: false, message: new Error('message') }); +e = new PluginError({ showProperties: false, showStack: false, message: new Error('message'), plugin: 'my-plugin' }); + +// without non-mandatory options +e = new PluginError('my-plugin', 'message', {}); +e = new PluginError('my-plugin', { message: 'message' }); +e = new PluginError({ message: 'message', plugin: 'my-plugin' }); + +// check Error base class +const f: Error = e; diff --git a/types/plugin-error/tsconfig.json b/types/plugin-error/tsconfig.json new file mode 100644 index 0000000000..ee9cd8e61f --- /dev/null +++ b/types/plugin-error/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "plugin-error-tests.ts" + ] +} diff --git a/types/plugin-error/tslint.json b/types/plugin-error/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/plugin-error/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }