export class $EventManager { private eventMap = new Map>(); //@ts-expect-error fire(type: K, ...args: EM[K]) { this.eventMap.get(type as string)?.forEach(fn => fn(...args as [])); return this } //@ts-expect-error on(type: K, callback: (...args: EM[K]) => any) { const set = this.eventMap.get(type as string) ?? this.eventMap.set(type as string, new Set()).get(type as string); set?.add(callback); return this } //@ts-expect-error off(type: K, callback: (...args: EM[K]) => any) { this.eventMap.get(type as string)?.delete(callback); return this } //@ts-expect-error once(type: K, callback: (...args: EM[K]) => any) { const onceFn = (...args: []) => { this.eventMap.get(type as string)?.delete(onceFn); //@ts-expect-error callback(...args); } const set = this.eventMap.get(type as string) ?? this.eventMap.set(type as string, new Set()).get(type as string) set?.add(onceFn); return this; } } export interface $EventMap {}