/** * A strongly‑typed EventEmitter. */ export default class EventEmitter> { private _maxListeners; /** * We store a set of the listeners for each event. */ private _listenerStore; setMaxListeners(max: number): this; /** * Subscribe to an event with a listener function. * @param eventName The event name (key of E). * @param listener A function that receives the emitted arguments. * @returns The emitter instance (for chaining). */ on(eventName: K, listener: Events[K]): this; /** * Subscribe to an event with a listener function. * @param eventName The event name (key of E). * @param listener A function that receives the emitted arguments. * @returns The emitter instance (for chaining). */ addListener(eventName: K, listener: Events[K]): this; /** * Subscribe to an event, handling it only once. Automatically removes * the listener after it fires the first time. * @param eventName The event name (key of E). * @param listener A function that receives the emitted arguments. * @returns The emitter instance (for chaining). */ once(eventName: K, listener: Events[K]): this; /** * Unsubscribe a previously subscribed listener. * @param eventName The event name (key of E). * @param listener The original function passed to `on` or `once`. * @returns The emitter instance (for chaining). */ off(eventName: K, listener: Events[K]): this; /** * Unsubscribe a previously subscribed listener. * @param eventName The event name (key of E). * @param listener The original function passed to `on` or `once`. * @returns The emitter instance (for chaining). */ removeListener(eventName: K, listener: Events[K]): this; /** * Emit (dispatch) an event with a variable number of arguments. * @param eventName The event name (key of E). * @param args The arguments to pass to subscribed listeners. */ emit(eventName: K, ...args: Parameters): void; /** * Returns the array of listener functions currently registered for a given event. * @param eventName The event name (key of E). * @returns An array of listener functions. */ listeners(eventName: K): Array<(...args: Parameters) => void>; /** * Returns the number of listeners for a given event. * @param eventName The event name (key of E). * @returns The number of listeners. */ listenerCount(eventName: K): number; /** * Removes all listeners for a given event, or all events if none is specified. * @param eventName Optional. If omitted, clears all events’ listeners. * @returns The emitter instance (for chaining). */ removeAllListeners(eventName?: K): this; }