/// import { EventEmitter } from "events"; /** * An events map is an interface that maps event names to their value, which * represents the type of the `on` listener. */ export interface EventsMap { [event: string]: any; } /** * The default events map, used if no EventsMap is given. Using this EventsMap * is equivalent to accepting all event names, and any data. */ export interface DefaultEventsMap { [event: string]: (...args: any[]) => void; } /** * Returns a union type containing all the keys of an event map. */ export declare type EventNames = keyof Map & (string | symbol); /** The tuple type representing the parameters of an event listener */ export declare type EventParams> = Parameters; /** * The event names that are either in ReservedEvents or in UserEvents */ export declare type ReservedOrUserEventNames = EventNames | EventNames; /** * Type of a listener of a user event or a reserved event. If `Ev` is in * `ReservedEvents`, the reserved event listener is returned. */ export declare type ReservedOrUserListener> = FallbackToUntypedListener ? ReservedEvents[Ev] : Ev extends EventNames ? UserEvents[Ev] : never>; /** * Returns an untyped listener type if `T` is `never`; otherwise, returns `T`. * * This is a hack to mitigate https://github.com/socketio/socket.io/issues/3833. * Needed because of https://github.com/microsoft/TypeScript/issues/41778 */ declare type FallbackToUntypedListener = [T] extends [never] ? (...args: any[]) => void | Promise : T; /** * Interface for classes that aren't `EventEmitter`s, but still expose a * strictly typed `emit` method. */ export interface TypedEventBroadcaster { emit>(ev: Ev, ...args: EventParams): boolean; } /** * Strictly typed version of an `EventEmitter`. A `TypedEventEmitter` takes type * parameters for mappings of event names to event data types, and strictly * types method calls to the `EventEmitter` according to these event maps. * * @typeParam ListenEvents - `EventsMap` of user-defined events that can be * listened to with `on` or `once` * @typeParam EmitEvents - `EventsMap` of user-defined events that can be * emitted with `emit` * @typeParam ReservedEvents - `EventsMap` of reserved events, that can be * emitted by socket.io with `emitReserved`, and can be listened to with * `listen`. */ export declare abstract class StrictEventEmitter extends EventEmitter implements TypedEventBroadcaster { /** * Adds the `listener` function as an event listener for `ev`. * * @param ev Name of the event * @param listener Callback function */ on>(ev: Ev, listener: ReservedOrUserListener): this; /** * Adds a one-time `listener` function as an event listener for `ev`. * * @param ev Name of the event * @param listener Callback function */ once>(ev: Ev, listener: ReservedOrUserListener): this; /** * Emits an event. * * @param ev Name of the event * @param args Values to send to listeners of this event */ emit>(ev: Ev, ...args: EventParams): boolean; /** * Emits a reserved event. * * This method is `protected`, so that only a class extending * `StrictEventEmitter` can emit its own reserved events. * * @param ev Reserved event name * @param args Arguments to emit along with the event */ protected emitReserved>(ev: Ev, ...args: EventParams): boolean; /** * Emits an event. * * This method is `protected`, so that only a class extending * `StrictEventEmitter` can get around the strict typing. This is useful for * calling `emit.apply`, which can be called as `emitUntyped.apply`. * * @param ev Event name * @param args Arguments to emit along with the event */ protected emitUntyped(ev: string, ...args: any[]): boolean; /** * Returns the listeners listening to an event. * * @param event Event name * @returns Array of listeners subscribed to `event` */ listeners>(event: Ev): ReservedOrUserListener[]; } export {};