mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
* Update serverless types This fixes a couple of inconsistencies with the type declarations: * `Plugin.hooks` is a dictionary of functions that return a promise, not a dictionary of promises * `serverless.service.provider.compiledCloudFormationTemplate.Resources` is an object rather than an array * make Plugin an interface instead of an abstract class * add provider.naming * add plugin constructor typedef as PluginStatic
49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
import Serverless from 'serverless';
|
|
import Plugin from 'serverless/classes/Plugin';
|
|
import PluginManager from 'serverless/classes/PluginManager';
|
|
|
|
const options: Serverless.Options = {
|
|
noDeploy: false,
|
|
stage: null,
|
|
region: '',
|
|
};
|
|
|
|
const serverless = new Serverless();
|
|
|
|
class CustomPlugin implements Plugin {
|
|
commands = {
|
|
command: {
|
|
usage: 'description',
|
|
lifecycleEvents: ['start'],
|
|
options: {
|
|
option: {
|
|
usage: `description`,
|
|
required: true,
|
|
shortcut: 'o',
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
customProp = {};
|
|
|
|
hooks: Plugin.Hooks;
|
|
|
|
constructor(serverless: Serverless, options: Serverless.Options) {
|
|
this.hooks = {
|
|
'command:start': () => {},
|
|
};
|
|
}
|
|
}
|
|
|
|
// Test a plugin with missing 'hooks' property
|
|
class BadPlugin implements Plugin { // $ExpectError
|
|
hoooks: Plugin.Hooks; // emulate a bad 'hooks' definition with a typo
|
|
constructor(badArg: number) {}
|
|
}
|
|
|
|
const manager = new PluginManager(serverless);
|
|
manager.addPlugin(CustomPlugin);
|
|
// Test adding a plugin with an incorrect constructor
|
|
manager.addPlugin(BadPlugin); // $ExpectError
|