import { EventEmitter } from "events"; type TEventName = string | symbol; type AnyListener = (...args: any[]) => void; type Arguments = TListener extends (...args: infer TArgs) => any ? TArgs : any[]; type Listener = TEvents[TEvent] extends (...args: infer TArgs) => any ? (...args: TArgs) => void : AnyListener; export interface DefaultEvents { newListener: (event: TEventName, listener: AnyListener) => void; removeListener: (event: TEventName, listener: AnyListener) => void; } export type AnyEvents = DefaultEvents & { [event in TEventName]: any[]; }; type IEventSubscriber = (event: TEvent, listener: Listener) => This; // tslint:disable:ban-types interface ITypedEventEmitter { on: IEventSubscriber; off: IEventSubscriber; once: IEventSubscriber; addListener: IEventSubscriber; removeListener: IEventSubscriber; prependListener: IEventSubscriber; prependOnceListener: IEventSubscriber; emit(event: TEvent, ...args: Arguments): boolean; listeners(event: TEvent): Function[]; rawListeners(event: TEvent): Function[]; eventNames(): Array; setMaxListeners(maxListeners: number): this; getMaxListeners(): number; listenerCount(event: TEvent): number; } const TypedEventEmitter = EventEmitter as { new(): TypedEventEmitter, }; type TypedEventEmitter = ITypedEventEmitter; export { TypedEventEmitter };