/** * The shape of the arguments tuple for when the default event map is used. * This is used to allow for any number of arguments to be passed to the event listeners. */ export declare type AnyRest = [...args: any[]]; /** * The shape of the arguments tuple for a specific event. * @typeParam K - The event name. * @typeParam T - The event map. */ export declare type Args = T extends DefaultEventMap ? AnyRest : K extends keyof T ? T[K] : never; /** * The shape of the default event map. */ export declare type DefaultEventMap = [never]; /** * Describes the shape of the internal event listener map. */ export declare interface EventListenerMap { [key: string | symbol]: Array<{ fn: (...args: any[]) => void; ctx: any; }>; } /** * The default shape of the event map. * @typeParam T - The event map. */ export declare type EventMap = Record | DefaultEventMap; /** * A utility type used to extract the event key from the event map. * @typeParam K - The event name. * @typeParam T - The event map. */ export declare type Key = T extends DefaultEventMap ? string | symbol : K | keyof T; /** * A utility type used to extract the keys from the event map. * @typeParam T - The event map. */ export declare type Keys = T extends DefaultEventMap ? string | symbol : keyof T; /** * A utility type used to extract the shape of the listener function from the event map. * @typeParam K - The event name. * @typeParam T - The event map. */ export declare type Listener = T extends DefaultEventMap ? (...args: any[]) => void : K extends keyof T ? T[K] extends unknown[] ? (...args: T[K]) => void : never : never; /** * A strongly-typed Tiny Event Emitter. */ export declare class TypedEventEmitter = DefaultEventMap> { /** * The internal event listener map for the emitter. */ e: EventListenerMap; /** * Creates a new TypedEventEmitter instance. */ constructor(); /** * Subscribe to an event with a typed listener. * @param event - The event name. * @param listener - The listener function. * @param ctx - The `this` context to apply to the listener when it is called * @returns the current instance for chaining */ on(event: Key, listener: Listener, ctx?: any): this; /** * Subscribe to an event once with a typed listener. * @param event - The event name. * @param listener - The listener function. * @param ctx - The `this` context to apply to the listener when it is called * @returns the current instance for chaining */ once(event: Key, listener: Listener, ctx?: any): this; /** * Emit an event. * @param event - The event name. * @param args - The arguments to pass to the listeners. * @returns the current instance for chaining */ emit(event: Key, ...args: Args): this; /** * Unsubscribe from an event. * @param event - The event name. * @param listener - Optional. The listener function to remove. * @returns the current instance for chaining * * @remarks When no listener is provided, all listeners for the event will be removed, otherwise * only the specified listener will be removed. */ off(event: Key, listener?: Listener): this; } /** * The current version of the package. */ export declare const version: string; export { }