Skip to content
Permalink
Browse files
feat(typings): add missing types for some emitter methods (#1502)
Co-authored-by: Abd UlHameed Maree <abd.maree@scandinaviatech.com>
  • Loading branch information
AbdUlHamedMaree and Abd UlHameed Maree committed Oct 14, 2021
1 parent 0661564 commit a9e5b85580e8edca0b0fd2850c3741d3d86a96e2
Showing with 54 additions and 0 deletions.
  1. +54 −0 lib/typed-events.ts
@@ -107,6 +107,20 @@ export abstract class StrictEventEmitter<
return this;
}

/**
* Removes the `listener` function as an event listener for `ev`.
*
* @param ev Name of the event
* @param listener Callback function
*/
off<Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents>>(
ev?: Ev,
listener?: ReservedOrUserListener<ReservedEvents, ListenEvents, Ev>
): this {
super.off(ev as string, listener);
return this;
}

/**
* Emits an event.
*
@@ -153,4 +167,44 @@ export abstract class StrictEventEmitter<
Ev
>[];
}

/**
* Returns true if there is a listener for this event.
*
* @param event Event name
* @returns boolean
*/
hasListeners<
Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents>
>(event: Ev): boolean {
return super.hasListeners(event as string);
}

/**
* Removes the `listener` function as an event listener for `ev`.
*
* @param ev Name of the event
* @param listener Callback function
*/
removeListener<
Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents>
>(
ev?: Ev,
listener?: ReservedOrUserListener<ReservedEvents, ListenEvents, Ev>
): this {
super.removeListener(ev as string, listener);
return this;
}

/**
* Removes all `listener` function as an event listener for `ev`.
*
* @param ev Name of the event
*/
removeAllListeners<
Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents>
>(ev?: Ev): this {
super.removeAllListeners(ev as string);
return this;
}
}

0 comments on commit a9e5b85

Please sign in to comment.