Skip to content

Commit

Permalink
fix: simplify typed EventEmitter
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnowack committed Aug 6, 2024
1 parent f502f01 commit 682761e
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions packages/signaldb/src/types/EventEmitter.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { EventEmitter as BaseEventEmitter } from 'events'

declare interface EventEmitter<T extends Record<string | symbol, any>> {
on<U extends keyof T>(
event: U, listener: T[U]
): this,

emit<U extends keyof T>(
event: U, ...args: Parameters<T[U]>
): boolean,
export default class EventEmitter<
Events extends Record<string | symbol, any>,
> extends BaseEventEmitter {
on<K extends keyof Events>(event: K, listener: Events[K]) {
super.on(event as string, listener as (...args: any[]) => void)
return this
}

emit<K extends keyof Events>(event: K, ...args: Parameters<Events[K]>) {
return super.emit(event as string, ...args)
}
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-unsafe-declaration-merging
class EventEmitter<T> extends BaseEventEmitter {}

export default EventEmitter

0 comments on commit 682761e

Please sign in to comment.