123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- declare class EventEmitter<
- EventTypes extends EventEmitter.ValidEventTypes = string | symbol,
- Context extends any = any
- > {
- static prefixed: string | boolean;
-
- eventNames(): Array<EventEmitter.EventNames<EventTypes>>;
-
- listeners<T extends EventEmitter.EventNames<EventTypes>>(
- event: T
- ): Array<EventEmitter.EventListener<EventTypes, T>>;
-
- listenerCount(event: EventEmitter.EventNames<EventTypes>): number;
-
- emit<T extends EventEmitter.EventNames<EventTypes>>(
- event: T,
- ...args: EventEmitter.EventArgs<EventTypes, T>
- ): boolean;
-
- on<T extends EventEmitter.EventNames<EventTypes>>(
- event: T,
- fn: EventEmitter.EventListener<EventTypes, T>,
- context?: Context
- ): this;
- addListener<T extends EventEmitter.EventNames<EventTypes>>(
- event: T,
- fn: EventEmitter.EventListener<EventTypes, T>,
- context?: Context
- ): this;
-
- once<T extends EventEmitter.EventNames<EventTypes>>(
- event: T,
- fn: EventEmitter.EventListener<EventTypes, T>,
- context?: Context
- ): this;
-
- removeListener<T extends EventEmitter.EventNames<EventTypes>>(
- event: T,
- fn?: EventEmitter.EventListener<EventTypes, T>,
- context?: Context,
- once?: boolean
- ): this;
- off<T extends EventEmitter.EventNames<EventTypes>>(
- event: T,
- fn?: EventEmitter.EventListener<EventTypes, T>,
- context?: Context,
- once?: boolean
- ): this;
-
- removeAllListeners(event?: EventEmitter.EventNames<EventTypes>): this;
- }
- declare namespace EventEmitter {
- export interface ListenerFn<Args extends any[] = any[]> {
- (...args: Args): void;
- }
- export interface EventEmitterStatic {
- new <
- EventTypes extends ValidEventTypes = string | symbol,
- Context = any
- >(): EventEmitter<EventTypes, Context>;
- }
-
- export type ValidEventTypes = string | symbol | object;
- export type EventNames<T extends ValidEventTypes> = T extends string | symbol
- ? T
- : keyof T;
- export type ArgumentMap<T extends object> = {
- [K in keyof T]: T[K] extends (...args: any[]) => void
- ? Parameters<T[K]>
- : T[K] extends any[]
- ? T[K]
- : any[];
- };
- export type EventListener<
- T extends ValidEventTypes,
- K extends EventNames<T>
- > = T extends string | symbol
- ? (...args: any[]) => void
- : (
- ...args: ArgumentMap<Exclude<T, string | symbol>>[Extract<K, keyof T>]
- ) => void;
- export type EventArgs<
- T extends ValidEventTypes,
- K extends EventNames<T>
- > = Parameters<EventListener<T, K>>;
- export const EventEmitter: EventEmitterStatic;
- }
- export { EventEmitter }
- export default EventEmitter;
|