removeAllListeners should allow no arguments
apowers313 opened this issue · 2 comments
apowers313 commented
Currently 'removeAllListeners' is defined as removeAllListeners(type: string | symbol): Promise<any>
, requiring a string
or symbol
argument. Per the node documentation, the argument is optional and if no argument is specified all listeners are removed.
yanickrochon commented
Hi @apowers313 I will gladly update the emitter.d.ts
file, however I'm not using TypeScript myself, so that file was submitted through contributions. Would simply changing the line
Line 24 in dcf73c6
to
removeAllListeners(type?: string | symbol): Promise<any>;
resolve the issue, or is there anything else?
yanickrochon commented
Since the type definition seems to also be missing a few properties, would this be a suitable update (again, I'm not using TypeScript, so I'm mostly flying blind on this issue) :
import type events from 'events';
type BaseEventEmitter = Omit<events.EventEmitter, 'emit'|'once'|'on'|'off'|'prependOnceListener'|'prependListener'|'addListener'|'removeListener'|'removeAllListeners'>;
declare type TEventType = string | symbol;
declare type TListener = (...args: any[]) => Promise<any>;
declare type TFilter<T = any> = {
<S extends T>(callbackfn: (value: T, index: number, array: T[]) => value is S, thisArg?: any): S[];
(callbackfn: (value: T, index: number, array: T[]) => unknown, thisArg?: any): T[];
}
interface EventEmitter extends BaseEventEmitter {}
declare class EventEmitter implements EventEmitter {
private _resultFilter;
private _events;
private _eventsCount;
private _domain;
get maxListeners(): number;
set maxListeners(n: number);
getResultFilter(): TFilter | undefined;
setResultFilter(filter: TFilter | undefined): this;
get resultFilter(): TFilter | undefined;
set resultFilter(filter: TFilter | undefined);
emit(type: TEventType, ...args: any[]): Promise<any>;
addListener(type: TEventType, listener: TListener): Promise<any>;
prependListener(type: TEventType, listener: TListener): Promise<any>;
once(type: TEventType, listener?: TListener): Promise<any>;
prependOnceListener(type: TEventType, listener: TListener): Promise<any>;
removeListener(type: TEventType, listener: TListener): Promise<any>;
removeAllListeners(type?: string | symbol): Promise<any>;
on(type: TEventType, listener: TListener): Promise<any>;
off(type: TEventType, listener: TListener): Promise<any>;
static EventEmitter: typeof EventEmitter;
static defaultMaxListeners: number | undefined;
static usingDomains: boolean | undefined;
static listenerCount: (events: EventEmitter, type: TEventType) => number;
}
export = EventEmitter;