Skip to content

Commit

Permalink
[TS typings] Fix typing for util.use(plugin, options) to allow strong…
Browse files Browse the repository at this point in the history
…ly typed plugin functions

Resolves error introduced in [email protected] where Derby app.use plugins had TS compile errors
  • Loading branch information
ericyhwang committed Jul 22, 2024
1 parent 3c7a014 commit 669dc87
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,16 +229,18 @@ export function serverUse(module, id: string, options?: unknown) {
return this.use(plugin, options);
}

type Plugin<T extends {}, O> = (pluginHost: T, options: O) => void;

/**
* Use plugin
*
* @param plugin
* @param options - Optional options passed to plugin
* @returns
*/
export function use(plugin: (arg0: unknown, options?: unknown) => void, options?: unknown) {
export function use<T extends {}, O>(this: T, plugin: Plugin<T, O>, options?: O) {
// Don't include a plugin more than once
var plugins = this._plugins || (this._plugins = []);
var plugins = (this as any)._plugins || ((this as any)._plugins = []);
if (plugins.indexOf(plugin) === -1) {
plugins.push(plugin);
plugin(this, options);
Expand Down

0 comments on commit 669dc87

Please sign in to comment.