Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removeAllListeners should allow no arguments #29

Open
apowers313 opened this issue Feb 8, 2022 · 2 comments
Open

removeAllListeners should allow no arguments #29

apowers313 opened this issue Feb 8, 2022 · 2 comments

Comments

@apowers313
Copy link

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
Copy link
Owner

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

removeAllListeners(type: string | symbol): Promise<any>;

to

 removeAllListeners(type?: string | symbol): Promise<any>; 

resolve the issue, or is there anything else?

@yanickrochon
Copy link
Owner

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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants