Skip to content

Commit 97499ad

Browse files
committed
feat: plugin helpers
1 parent 8e8ed14 commit 97499ad

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/Utils.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
import { EventEmitter } from 'node:events';
22

3+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type, @typescript-eslint/no-empty-object-type
4+
interface AnyClass<InstanceType extends {} = {}> extends Function {
5+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
6+
new(...args: any[]): InstanceType;
7+
prototype: InstanceType;
8+
}
9+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
10+
export type AnyFunction = (...args: any) => any;
311
export type Extension = Record<string, unknown>;
412
export type Plugin<T> = (instance: T) => Extension;
513

14+
export const definePlugin = <T extends AnyClass, B extends AnyFunction = Plugin<T>>(plugin: B): B => plugin;
15+
616
// https://stackoverflow.com/a/58603027
7-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
8-
export function withPlugins<TBase extends new (...args: any[]) => any>(Base: TBase) {
17+
export function withPlugins<TBase extends AnyClass>(Base: TBase) {
918
return class ClassWithPlugins extends Base {
1019
static plugins: Plugin<ClassWithPlugins>[];
1120
static plugin<T extends Plugin<ClassWithPlugins>>(plugin: T) {

0 commit comments

Comments
 (0)