Add typings for plugin-error

This commit is contained in:
Rogier Schouten
2017-12-25 16:28:52 +01:00
parent 710943739f
commit ff530246cf
4 changed files with 105 additions and 0 deletions

58
types/plugin-error/index.d.ts vendored Normal file
View File

@@ -0,0 +1,58 @@
// Type definitions for plugin-error 0.1
// Project: https://github.com/jonschlinkert/plugin-error
// Definitions by: Rogier Schouten <https://github.com/rogierschouten>
// 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;
}

View File

@@ -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;

View File

@@ -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"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }