UNPKG

sub-events

Version:

Lightweight, strongly-typed events, with monitored subscriptions.

22 lines (21 loc) 946 B
import { IEmitOptions, SubEventCount } from '../dist/src'; /** * Helps supporting any custom EventEmitter-like type. */ interface IEmitterLike { addListener: (event: string | symbol, listener: (...args: any[]) => void) => this; removeListener: (event: string | symbol, listener: (...args: any[]) => void) => this; } /** * Creates a named event from emitter, for one-argument, strongly-typed events. * * If your event takes multiple arguments, see fromEmitterArgs below. */ export declare function fromEmitter<T = unknown>(target: IEmitterLike, event: string | symbol, options?: IEmitOptions): SubEventCount<T>; /** * Creates a named event from emitter, for multi-argument, tuple-type events. * * The emitted arguments are passed into the handler as a tuple array. */ export declare function fromEmitterArgs<T extends unknown[]>(target: IEmitterLike, event: string | symbol, options?: IEmitOptions): SubEventCount<T>; export {};