mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-07 17:17:23 +08:00
Add typings for plugin-error
This commit is contained in:
58
types/plugin-error/index.d.ts
vendored
Normal file
58
types/plugin-error/index.d.ts
vendored
Normal 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;
|
||||
}
|
||||
23
types/plugin-error/plugin-error-tests.ts
Normal file
23
types/plugin-error/plugin-error-tests.ts
Normal 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;
|
||||
23
types/plugin-error/tsconfig.json
Normal file
23
types/plugin-error/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
1
types/plugin-error/tslint.json
Normal file
1
types/plugin-error/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user