NOTE: This class is in the docs but is not actually exported by Node.
If https://github.com/nodejs/node/issues/39903 gets resolved and Node
actually starts exporting the class, uncomment below.
import { EventListener, EventListenerObject } from '__dom-events';
/** The NodeEventTarget is a Node.js-specific extension to EventTarget that emulates a subset of the EventEmitter API. /
interface NodeEventTarget extends EventTarget {
/*
* Node.js-specific extension to the EventTarget class that emulates the equivalent EventEmitter API.
* The only difference between addListener() and addEventListener() is that addListener() will return a reference to the EventTarget.
/
addListener(type: string, listener: EventListener | EventListenerObject, options?: { once: boolean }): this;
/* Node.js-specific extension to the EventTarget class that returns an array of event type names for which event listeners are registered. /
eventNames(): string[];
/* Node.js-specific extension to the EventTarget class that returns the number of event listeners registered for the type. /
listenerCount(type: string): number;
/* Node.js-specific alias for eventTarget.removeListener(). /
off(type: string, listener: EventListener | EventListenerObject): this;
/* Node.js-specific alias for eventTarget.addListener(). /
on(type: string, listener: EventListener | EventListenerObject, options?: { once: boolean }): this;
/* Node.js-specific extension to the EventTarget class that adds a once listener for the given event type. This is equivalent to calling on with the once option set to true. /
once(type: string, listener: EventListener | EventListenerObject): this;
/*
* Node.js-specific extension to the EventTarget class.
* If type is specified, removes all registered listeners for type,
* otherwise removes all registered listeners.
/
removeAllListeners(type: string): this;
/*
* Node.js-specific extension to the EventTarget class that removes the listener for the given type.
* The only difference between removeListener() and removeEventListener() is that removeListener() will return a reference to the EventTarget.
*/
removeListener(type: string, listener: EventListener | EventListenerObject): this;
}
NOTE: This class is in the docs but is not actually exported by Node. If https://github.com/nodejs/node/issues/39903 gets resolved and Node actually starts exporting the class, uncomment below. import { EventListener, EventListenerObject } from '__dom-events'; /** The NodeEventTarget is a Node.js-specific extension to EventTarget that emulates a subset of the EventEmitter API. / interface NodeEventTarget extends EventTarget { /* * Node.js-specific extension to the
EventTarget
class that emulates the equivalentEventEmitter
API. * The only difference betweenaddListener()
andaddEventListener()
is that addListener() will return a reference to the EventTarget. / addListener(type: string, listener: EventListener | EventListenerObject, options?: { once: boolean }): this; /* Node.js-specific extension to theEventTarget
class that returns an array of eventtype
names for which event listeners are registered. / eventNames(): string[]; /* Node.js-specific extension to theEventTarget
class that returns the number of event listeners registered for thetype
. / listenerCount(type: string): number; /* Node.js-specific alias foreventTarget.removeListener()
. / off(type: string, listener: EventListener | EventListenerObject): this; /* Node.js-specific alias foreventTarget.addListener()
. / on(type: string, listener: EventListener | EventListenerObject, options?: { once: boolean }): this; /* Node.js-specific extension to theEventTarget
class that adds aonce
listener for the given eventtype
. This is equivalent to callingon
with theonce
option set totrue
. / once(type: string, listener: EventListener | EventListenerObject): this; /* * Node.js-specific extension to theEventTarget
class. * Iftype
is specified, removes all registered listeners fortype
, * otherwise removes all registered listeners. / removeAllListeners(type: string): this; /* * Node.js-specific extension to theEventTarget
class that removes the listener for the giventype
. * The only difference betweenremoveListener()
andremoveEventListener()
is thatremoveListener()
will return a reference to theEventTarget
. */ removeListener(type: string, listener: EventListener | EventListenerObject): this; }