@types/node
Advanced tools
Comparing version 16.18.116 to 16.18.117
@@ -37,2 +37,3 @@ /** | ||
*/ | ||
declare module "events" { | ||
@@ -60,21 +61,29 @@ import { AsyncResource, AsyncResourceOptions } from "node:async_hooks"; | ||
interface StaticEventEmitterOptions { | ||
/** | ||
* Can be used to cancel awaiting events. | ||
*/ | ||
signal?: AbortSignal | undefined; | ||
} | ||
interface EventEmitter<T extends EventMap<T> = DefaultEventMap> extends NodeJS.EventEmitter<T> {} | ||
type EventMap<T> = Record<keyof T, any[]> | DefaultEventMap; | ||
type DefaultEventMap = [never]; | ||
type AnyRest = [...args: any[]]; | ||
type Args<K, T> = T extends DefaultEventMap ? AnyRest : ( | ||
K extends keyof T ? T[K] : never | ||
); | ||
type Key<K, T> = T extends DefaultEventMap ? string | symbol : K | keyof T; | ||
type Key2<K, T> = T extends DefaultEventMap ? string | symbol : K & keyof T; | ||
type Listener<K, T, F> = T extends DefaultEventMap ? F : ( | ||
K extends keyof T ? ( | ||
T[K] extends unknown[] ? (...args: T[K]) => void : never | ||
) | ||
: never | ||
); | ||
type Listener1<K, T> = Listener<K, T, (...args: any[]) => void>; | ||
type Listener2<K, T> = Listener<K, T, Function>; | ||
interface EventEmitter<Events extends EventMap<Events> = {}> extends NodeJS.EventEmitter<Events> {} | ||
type EventMap<Events> = Record<keyof Events, unknown[]>; | ||
type Args<Events extends EventMap<Events>, EventName> = EventName extends keyof Events ? ( | ||
| Events[EventName] | ||
| (EventName extends keyof EventEmitter.EventEmitterBuiltInEventMap | ||
? EventEmitter.EventEmitterBuiltInEventMap[EventName] | ||
: never) | ||
) | ||
: (EventName extends keyof EventEmitter.EventEmitterBuiltInEventMap | ||
? EventEmitter.EventEmitterBuiltInEventMap[EventName] | ||
: any[]); | ||
type EventNames<Events extends EventMap<Events>> = {} extends Events ? (string | symbol) | ||
: (keyof Events | keyof EventEmitter.EventEmitterBuiltInEventMap); | ||
type Listener<Events extends EventMap<Events>, EventName> = EventName extends keyof Events ? | ||
| ((...args: Events[EventName]) => void) | ||
| (EventName extends keyof EventEmitter.EventEmitterBuiltInEventMap | ||
? (...args: EventEmitter.EventEmitterBuiltInEventMap[EventName]) => void | ||
: never) | ||
: (EventName extends keyof EventEmitter.EventEmitterBuiltInEventMap | ||
? (...args: EventEmitter.EventEmitterBuiltInEventMap[EventName]) => void | ||
: (...args: any[]) => void); | ||
/** | ||
@@ -93,7 +102,17 @@ * The `EventEmitter` class is defined and exposed by the `events` module: | ||
*/ | ||
class EventEmitter<T extends EventMap<T> = DefaultEventMap> { | ||
class EventEmitter<Events extends EventMap<Events> = {}> { | ||
constructor(options?: EventEmitterOptions); | ||
[EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: Key<K, T>, ...args: Args<K, T>): void; | ||
// This "property" is used to brand a specific instance of the EventEmitter class with its Event map, which is needed | ||
// in order to infer the map if we have a chain like `class A extends EventEmitter<{}>` (or many levels deep) | ||
// It is also marked as possibly undefined in order to allow something like `const t: NodeJS.EventEmitter<{}> = { <insert implementation here> };` | ||
readonly #internalTypeOnlyBrand?: Events; | ||
[EventEmitter.captureRejectionSymbol]?<EventName extends EventNames<Events>>( | ||
error: Error, | ||
event: EventName, | ||
...args: Args<Events, EventName> | ||
): void; | ||
[EventEmitter.captureRejectionSymbol]?(error: Error, event: string | symbol, ...args: any[]): void; | ||
/** | ||
@@ -136,3 +155,3 @@ * Creates a `Promise` that is fulfilled when the `EventEmitter` emits the given | ||
* | ||
* The special handling of the `'error'` event is only used when `events.once()`is used to wait for another event. If `events.once()` is used to wait for the | ||
* The special handling of the `'error'` event is only used when `events.once()` is used to wait for another event. If `events.once()` is used to wait for the | ||
* '`error'` event itself, then it is treated as any other kind of event without | ||
@@ -148,3 +167,3 @@ * special handling: | ||
* .then(([err]) => console.log('ok', err.message)) | ||
* .catch((err) => console.log('error', err.message)); | ||
* .catch((err) => console.error('error', err.message)); | ||
* | ||
@@ -183,2 +202,7 @@ * ee.emit('error', new Error('boom')); | ||
*/ | ||
static once<Events extends EventMap<Events>, EventName extends EventNames<Events>>( | ||
emitter: EventEmitter<Events>, | ||
eventName: EventName, | ||
options?: StaticEventEmitterOptions, | ||
): Promise<Args<Events, EventName>>; | ||
static once( | ||
@@ -245,12 +269,16 @@ emitter: NodeEventTarget, | ||
* @since v13.6.0, v12.16.0 | ||
* @param eventName The name of the event being listened for | ||
* @return that iterates `eventName` events emitted by the `emitter` | ||
* @return An `AsyncIterator` that iterates `eventName` events emitted by the `emitter` | ||
*/ | ||
static on<Events extends EventMap<Events>, EventName extends EventNames<Events>>( | ||
emitter: EventEmitter<Events>, | ||
eventName: EventName, | ||
options?: StaticEventEmitterOptions, | ||
): NodeJS.AsyncIterator<Args<Events, EventName>>; | ||
static on( | ||
emitter: NodeJS.EventEmitter, | ||
eventName: string, | ||
eventName: string | symbol, | ||
options?: StaticEventEmitterOptions, | ||
): NodeJS.AsyncIterator<any>; | ||
): NodeJS.AsyncIterator<any[]>; | ||
/** | ||
* A class method that returns the number of listeners for the given `eventName`registered on the given `emitter`. | ||
* A class method that returns the number of listeners for the given `eventName` registered on the given `emitter`. | ||
* | ||
@@ -270,2 +298,23 @@ * ```js | ||
*/ | ||
static listenerCount<Events extends EventMap<Events>, EventName extends EventNames<Events>>( | ||
emitter: EventEmitter<Events>, | ||
eventName: EventName, | ||
): number; | ||
/** | ||
* A class method that returns the number of listeners for the given `eventName` registered on the given `emitter`. | ||
* | ||
* ```js | ||
* const { EventEmitter, listenerCount } = require('events'); | ||
* | ||
* const myEmitter = new EventEmitter(); | ||
* myEmitter.on('event', () => {}); | ||
* myEmitter.on('event', () => {}); | ||
* console.log(listenerCount(myEmitter, 'event')); | ||
* // Prints: 2 | ||
* ``` | ||
* @since v0.9.12 | ||
* @deprecated Since v3.2.0 - Use `listenerCount` instead. | ||
* @param emitter The emitter to query | ||
* @param eventName The event name | ||
*/ | ||
static listenerCount(emitter: NodeJS.EventEmitter, eventName: string | symbol): number; | ||
@@ -288,3 +337,3 @@ /** | ||
* ee.on('foo', listener); | ||
* getEventListeners(ee, 'foo'); // [listener] | ||
* console.log(getEventListeners(ee, 'foo')); // [ [Function: listener] ] | ||
* } | ||
@@ -295,7 +344,11 @@ * { | ||
* et.addEventListener('foo', listener); | ||
* getEventListeners(et, 'foo'); // [listener] | ||
* console.log(getEventListeners(et, 'foo')); // [ [Function: listener] ] | ||
* } | ||
* ``` | ||
* @since v15.2.0 | ||
* @since v15.2.0, v14.17.0 | ||
*/ | ||
static getEventListeners<Events extends EventMap<Events>, EventName extends EventNames<Events>>( | ||
emitter: EventEmitter<Events>, | ||
name: EventName, | ||
): Array<Listener<Events, EventName>>; | ||
static getEventListeners(emitter: DOMEventTarget | NodeJS.EventEmitter, name: string | symbol): Function[]; | ||
@@ -321,17 +374,61 @@ /** | ||
/** | ||
* This symbol shall be used to install a listener for only monitoring `'error'` | ||
* events. Listeners installed using this symbol are called before the regular | ||
* `'error'` listeners are called. | ||
* This symbol shall be used to install a listener for only monitoring `'error'` events. Listeners installed using this symbol are called before the regular `'error'` listeners are called. | ||
* | ||
* Installing a listener using this symbol does not change the behavior once an | ||
* `'error'` event is emitted, therefore the process will still crash if no | ||
* Installing a listener using this symbol does not change the behavior once an `'error'` event is emitted. Therefore, the process will still crash if no | ||
* regular `'error'` listener is installed. | ||
* @since v13.6.0, v12.17.0 | ||
*/ | ||
static readonly errorMonitor: unique symbol; | ||
/** | ||
* Value: `Symbol.for('nodejs.rejection')` | ||
* | ||
* See how to write a custom `rejection handler`. | ||
* @since v13.4.0, v12.16.0 | ||
*/ | ||
static readonly captureRejectionSymbol: unique symbol; | ||
/** | ||
* Sets or gets the default captureRejection value for all emitters. | ||
* Value: [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type) | ||
* | ||
* Change the default `captureRejections` option on all new `EventEmitter` objects. | ||
* @since v13.4.0, v12.16.0 | ||
*/ | ||
// TODO: These should be described using static getter/setter pairs: | ||
static captureRejections: boolean; | ||
/** | ||
* By default, a maximum of `10` listeners can be registered for any single | ||
* event. This limit can be changed for individual `EventEmitter` instances | ||
* using the `emitter.setMaxListeners(n)` method. To change the default | ||
* for _all_`EventEmitter` instances, the `events.defaultMaxListeners` property | ||
* can be used. If this value is not a positive number, a `RangeError` is thrown. | ||
* | ||
* Take caution when setting the `events.defaultMaxListeners` because the | ||
* change affects _all_ `EventEmitter` instances, including those created before | ||
* the change is made. However, calling `emitter.setMaxListeners(n)` still has | ||
* precedence over `events.defaultMaxListeners`. | ||
* | ||
* This is not a hard limit. The `EventEmitter` instance will allow | ||
* more listeners to be added but will output a trace warning to stderr indicating | ||
* that a "possible EventEmitter memory leak" has been detected. For any single | ||
* `EventEmitter`, the `emitter.getMaxListeners()` and `emitter.setMaxListeners()` methods can be used to | ||
* temporarily avoid this warning: | ||
* | ||
* ```js | ||
* const EventEmitter = require('events'); | ||
* const emitter = new EventEmitter(); | ||
* emitter.setMaxListeners(emitter.getMaxListeners() + 1); | ||
* emitter.once('event', () => { | ||
* // do stuff | ||
* emitter.setMaxListeners(Math.max(emitter.getMaxListeners() - 1, 0)); | ||
* }); | ||
* ``` | ||
* | ||
* The `--trace-warnings` command-line flag can be used to display the | ||
* stack trace for such warnings. | ||
* | ||
* The emitted warning can be inspected with `process.on('warning')` and will | ||
* have the additional `emitter`, `type`, and `count` properties, referring to | ||
* the event emitter instance, the event's name and the number of attached | ||
* listeners, respectively. | ||
* Its `name` property is set to `'MaxListenersExceededWarning'`. | ||
* @since v0.11.2 | ||
*/ | ||
static defaultMaxListeners: number; | ||
@@ -364,9 +461,37 @@ } | ||
/** | ||
* Integrates `EventEmitter` with `AsyncResource` for `EventEmitter`s that require | ||
* manual async tracking. Specifically, all events emitted by instances of | ||
* `EventEmitterAsyncResource` will run within its async context. | ||
* Integrates `EventEmitter` with `AsyncResource` for `EventEmitter`s that | ||
* require manual async tracking. Specifically, all events emitted by instances | ||
* of `events.EventEmitterAsyncResource` will run within its `async context`. | ||
* | ||
* The EventEmitterAsyncResource class has the same methods and takes the | ||
* same options as EventEmitter and AsyncResource themselves. | ||
* @throws if `options.name` is not provided when instantiated directly. | ||
* ```js | ||
* const { EventEmitterAsyncResource, EventEmitter } = require('events'); | ||
* const { notStrictEqual, strictEqual } = require('assert'); | ||
* const { executionAsyncId, triggerAsyncId } = require('async_hooks'); | ||
* | ||
* // Async tracking tooling will identify this as 'Q'. | ||
* const ee1 = new EventEmitterAsyncResource({ name: 'Q' }); | ||
* | ||
* // 'foo' listeners will run in the EventEmitters async context. | ||
* ee1.on('foo', () => { | ||
* strictEqual(executionAsyncId(), ee1.asyncId); | ||
* strictEqual(triggerAsyncId(), ee1.triggerAsyncId); | ||
* }); | ||
* | ||
* const ee2 = new EventEmitter(); | ||
* | ||
* // 'foo' listeners on ordinary EventEmitters that do not track async | ||
* // context, however, run in the same async context as the emit(). | ||
* ee2.on('foo', () => { | ||
* notStrictEqual(executionAsyncId(), ee2.asyncId); | ||
* notStrictEqual(triggerAsyncId(), ee2.triggerAsyncId); | ||
* }); | ||
* | ||
* Promise.resolve().then(() => { | ||
* ee1.emit('foo'); | ||
* ee2.emit('foo'); | ||
* }); | ||
* ``` | ||
* | ||
* The `EventEmitterAsyncResource` class has the same methods and takes the | ||
* same options as `EventEmitter` and `AsyncResource` themselves. | ||
* @since v17.4.0, v16.14.0 | ||
@@ -380,20 +505,41 @@ */ | ||
/** | ||
* Call all destroy hooks. This should only ever be called once. An | ||
* error will be thrown if it is called more than once. This must be | ||
* manually called. If the resource is left to be collected by the GC then | ||
* the destroy hooks will never be called. | ||
* Call all `destroy` hooks. This should only ever be called once. An error will | ||
* be thrown if it is called more than once. This **must** be manually called. If | ||
* the resource is left to be collected by the GC then the `destroy` hooks will | ||
* never be called. | ||
*/ | ||
emitDestroy(): void; | ||
/** The unique asyncId assigned to the resource. */ | ||
/** | ||
* The unique `asyncId` assigned to the resource. | ||
*/ | ||
readonly asyncId: number; | ||
/** The same triggerAsyncId that is passed to the AsyncResource constructor. */ | ||
/** | ||
* The same triggerAsyncId that is passed to the AsyncResource constructor. | ||
*/ | ||
readonly triggerAsyncId: number; | ||
/** The underlying AsyncResource */ | ||
/** | ||
* The returned `AsyncResource` object has an additional `eventEmitter` property | ||
* that provides a reference to this `EventEmitterAsyncResource`. | ||
*/ | ||
readonly asyncResource: EventEmitterReferencingAsyncResource; | ||
} | ||
export interface EventEmitterBuiltInEventMap { | ||
newListener: [eventName: string | symbol, listener: Function]; | ||
removeListener: [eventName: string | symbol, listener: Function]; | ||
} | ||
} | ||
global { | ||
namespace NodeJS { | ||
interface EventEmitter<T extends EventMap<T> = DefaultEventMap> { | ||
[EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: Key<K, T>, ...args: Args<K, T>): void; | ||
interface EventEmitter<Events extends EventMap<Events> = {}> { | ||
[EventEmitter.captureRejectionSymbol]?<EventName extends EventNames<Events>>( | ||
error: Error, | ||
event: EventName, | ||
...args: Args<Events, EventName> | ||
): void; | ||
[EventEmitter.captureRejectionSymbol]?<EventName extends string | symbol>( | ||
error: Error, | ||
event: EventName, | ||
...args: Args<Events, EventName> | ||
): void; | ||
/** | ||
@@ -403,8 +549,15 @@ * Alias for `emitter.on(eventName, listener)`. | ||
*/ | ||
addListener<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this; | ||
addListener<EventName extends EventNames<Events>>( | ||
eventName: EventName, | ||
listener: Listener<Events, EventName>, | ||
): this; | ||
addListener<EventName extends string | symbol>( | ||
eventName: EventName, | ||
listener: Listener<Events, EventName>, | ||
): this; | ||
/** | ||
* Adds the `listener` function to the end of the listeners array for the | ||
* event named `eventName`. No checks are made to see if the `listener` has | ||
* already been added. Multiple calls passing the same combination of `eventName` and `listener` will result in the `listener` being added, and called, multiple | ||
* times. | ||
* Adds the `listener` function to the end of the listeners array for the event | ||
* named `eventName`. No checks are made to see if the `listener` has already | ||
* been added. Multiple calls passing the same combination of `eventName` and | ||
* `listener` will result in the `listener` being added, and called, multiple times. | ||
* | ||
@@ -419,6 +572,7 @@ * ```js | ||
* | ||
* By default, event listeners are invoked in the order they are added. The`emitter.prependListener()` method can be used as an alternative to add the | ||
* By default, event listeners are invoked in the order they are added. The `emitter.prependListener()` method can be used as an alternative to add the | ||
* event listener to the beginning of the listeners array. | ||
* | ||
* ```js | ||
* const EventEmitter = require('events'); | ||
* const myEE = new EventEmitter(); | ||
@@ -436,5 +590,12 @@ * myEE.on('foo', () => console.log('a')); | ||
*/ | ||
on<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this; | ||
on<EventName extends EventNames<Events>>( | ||
eventName: EventName, | ||
listener: Listener<Events, EventName>, | ||
): this; | ||
on<EventName extends string | symbol>( | ||
eventName: EventName, | ||
listener: Listener<Events, EventName>, | ||
): this; | ||
/** | ||
* Adds a **one-time**`listener` function for the event named `eventName`. The | ||
* Adds a **one-time** `listener` function for the event named `eventName`. The | ||
* next time `eventName` is triggered, this listener is removed and then invoked. | ||
@@ -450,6 +611,7 @@ * | ||
* | ||
* By default, event listeners are invoked in the order they are added. The`emitter.prependOnceListener()` method can be used as an alternative to add the | ||
* By default, event listeners are invoked in the order they are added. The `emitter.prependOnceListener()` method can be used as an alternative to add the | ||
* event listener to the beginning of the listeners array. | ||
* | ||
* ```js | ||
* const EventEmitter = require('events'); | ||
* const myEE = new EventEmitter(); | ||
@@ -467,5 +629,12 @@ * myEE.once('foo', () => console.log('a')); | ||
*/ | ||
once<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this; | ||
once<EventName extends EventNames<Events>>( | ||
eventName: EventName, | ||
listener: Listener<Events, EventName>, | ||
): this; | ||
once<EventName extends string | symbol>( | ||
eventName: EventName, | ||
listener: Listener<Events, EventName>, | ||
): this; | ||
/** | ||
* Removes the specified `listener` from the listener array for the event named`eventName`. | ||
* Removes the specified `listener` from the listener array for the event named `eventName`. | ||
* | ||
@@ -487,6 +656,8 @@ * ```js | ||
* Once an event is emitted, all listeners attached to it at the | ||
* time of emitting are called in order. This implies that any`removeListener()` or `removeAllListeners()` calls _after_ emitting and_before_ the last listener finishes execution will | ||
* not remove them from`emit()` in progress. Subsequent events behave as expected. | ||
* time of emitting are called in order. This implies that any `removeListener()` or `removeAllListeners()` calls _after_ emitting and _before_ the last listener finishes execution | ||
* will not remove them from`emit()` in progress. Subsequent events behave as expected. | ||
* | ||
* ```js | ||
* const EventEmitter = require('events'); | ||
* class MyEmitter extends EventEmitter {} | ||
* const myEmitter = new MyEmitter(); | ||
@@ -529,5 +700,6 @@ * | ||
* event (as in the example below), `removeListener()` will remove the most | ||
* recently added instance. In the example the `once('ping')`listener is removed: | ||
* recently added instance. In the example the `once('ping')` listener is removed: | ||
* | ||
* ```js | ||
* const EventEmitter = require('events'); | ||
* const ee = new EventEmitter(); | ||
@@ -550,3 +722,10 @@ * | ||
*/ | ||
removeListener<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this; | ||
removeListener<EventName extends EventNames<Events>>( | ||
eventName: EventName, | ||
listener: Listener<Events, EventName>, | ||
): this; | ||
removeListener<EventName extends string | symbol>( | ||
eventName: EventName, | ||
listener: Listener<Events, EventName>, | ||
): this; | ||
/** | ||
@@ -556,3 +735,10 @@ * Alias for `emitter.removeListener()`. | ||
*/ | ||
off<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this; | ||
off<EventName extends EventNames<Events>>( | ||
eventName: EventName, | ||
listener: Listener<Events, EventName>, | ||
): this; | ||
off<EventName extends string | symbol>( | ||
eventName: EventName, | ||
listener: Listener<Events, EventName>, | ||
): this; | ||
/** | ||
@@ -568,3 +754,6 @@ * Removes all listeners, or those of the specified `eventName`. | ||
*/ | ||
removeAllListeners(event?: Key<unknown, T>): this; | ||
/* eslint-disable @definitelytyped/no-unnecessary-generics */ | ||
removeAllListeners<EventName extends EventNames<Events>>(eventName: EventName): this; | ||
removeAllListeners<EventName extends string | symbol>(eventName?: EventName): this; | ||
/* eslint-enable @definitelytyped/no-unnecessary-generics */ | ||
/** | ||
@@ -574,3 +763,3 @@ * By default `EventEmitter`s will print a warning if more than `10` listeners are | ||
* memory leaks. The `emitter.setMaxListeners()` method allows the limit to be | ||
* modified for this specific `EventEmitter` instance. The value can be set to`Infinity` (or `0`) to indicate an unlimited number of listeners. | ||
* modified for this specific `EventEmitter` instance. The value can be set to `Infinity` (or `0`) to indicate an unlimited number of listeners. | ||
* | ||
@@ -599,3 +788,8 @@ * Returns a reference to the `EventEmitter`, so that calls can be chained. | ||
*/ | ||
listeners<K>(eventName: Key<K, T>): Array<Listener2<K, T>>; | ||
listeners<EventName extends EventNames<Events>>( | ||
eventName: EventName, | ||
): Array<Listener<Events, EventName>>; | ||
listeners<EventName extends string | symbol>( | ||
eventName: EventName, | ||
): Array<Listener<Events, EventName>>; | ||
/** | ||
@@ -606,2 +800,3 @@ * Returns a copy of the array of listeners for the event named `eventName`, | ||
* ```js | ||
* const EventEmitter = require('events'); | ||
* const emitter = new EventEmitter(); | ||
@@ -631,5 +826,10 @@ * emitter.once('log', () => console.log('log once')); | ||
*/ | ||
rawListeners<K>(eventName: Key<K, T>): Array<Listener2<K, T>>; | ||
rawListeners<EventName extends EventNames<Events>>( | ||
eventName: EventName, | ||
): Array<Listener<Events, EventName>>; | ||
rawListeners<EventName extends string | symbol>( | ||
eventName: EventName, | ||
): Array<Listener<Events, EventName>>; | ||
/** | ||
* Synchronously calls each of the listeners registered for the event named`eventName`, in the order they were registered, passing the supplied arguments | ||
* Synchronously calls each of the listeners registered for the event named `eventName`, in the order they were registered, passing the supplied arguments | ||
* to each. | ||
@@ -673,14 +873,31 @@ * | ||
*/ | ||
emit<K>(eventName: Key<K, T>, ...args: Args<K, T>): boolean; | ||
emit<EventName extends EventNames<Events>>( | ||
eventName: EventName, | ||
...args: Args<Events, EventName> | ||
): boolean; | ||
emit<EventName extends string | symbol>( | ||
eventName: EventName, | ||
...args: Args<Events, EventName> | ||
): boolean; | ||
/** | ||
* Returns the number of listeners listening to the event named `eventName`. | ||
* Returns the number of listeners listening for the event named `eventName`. | ||
* If `listener` is provided, it will return how many times the listener is found | ||
* in the list of the listeners of the event. | ||
* @since v3.2.0 | ||
* @param eventName The name of the event being listened for | ||
* @param listener The event handler function | ||
*/ | ||
listenerCount<K>(eventName: Key<K, T>, listener?: Listener2<K, T>): number; | ||
listenerCount<EventName extends EventNames<Events>>( | ||
eventName: EventName, | ||
listener?: Listener<Events, EventName>, | ||
): number; | ||
listenerCount<EventName extends string | symbol>( | ||
eventName: EventName, | ||
listener?: Listener<Events, EventName>, | ||
): number; | ||
/** | ||
* Adds the `listener` function to the _beginning_ of the listeners array for the | ||
* event named `eventName`. No checks are made to see if the `listener` has | ||
* already been added. Multiple calls passing the same combination of `eventName` and `listener` will result in the `listener` being added, and called, multiple | ||
* times. | ||
* already been added. Multiple calls passing the same combination of `eventName` | ||
* and `listener` will result in the `listener` being added, and called, multiple times. | ||
* | ||
@@ -698,5 +915,12 @@ * ```js | ||
*/ | ||
prependListener<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this; | ||
prependListener<EventName extends EventNames<Events>>( | ||
eventName: EventName, | ||
listener: Listener<Events, EventName>, | ||
): this; | ||
prependListener<EventName extends string | symbol>( | ||
eventName: EventName, | ||
listener: Listener<Events, EventName>, | ||
): this; | ||
/** | ||
* Adds a **one-time**`listener` function for the event named `eventName` to the_beginning_ of the listeners array. The next time `eventName` is triggered, this | ||
* Adds a **one-time**`listener` function for the event named `eventName` to the _beginning_ of the listeners array. The next time `eventName` is triggered, this | ||
* listener is removed, and then invoked. | ||
@@ -715,3 +939,10 @@ * | ||
*/ | ||
prependOnceListener<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this; | ||
prependOnceListener<EventName extends EventNames<Events>>( | ||
eventName: EventName, | ||
listener: Listener<Events, EventName>, | ||
): this; | ||
prependOnceListener<EventName extends string | symbol>( | ||
eventName: EventName, | ||
listener: Listener<Events, EventName>, | ||
): this; | ||
/** | ||
@@ -735,3 +966,3 @@ * Returns an array listing the events for which the emitter has registered | ||
*/ | ||
eventNames(): Array<(string | symbol) & Key2<unknown, T>>; | ||
eventNames(): Array<(string | symbol)> & Array<EventNames<Events>>; | ||
} | ||
@@ -738,0 +969,0 @@ } |
{ | ||
"name": "@types/node", | ||
"version": "16.18.116", | ||
"version": "16.18.117", | ||
"description": "TypeScript definitions for node", | ||
@@ -221,4 +221,4 @@ "homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node", | ||
"peerDependencies": {}, | ||
"typesPublisherContentHash": "89bf8903de3ba398de8f681a07b47774e7bd8cc7ee302ce637d310f2781cf850", | ||
"typesPublisherContentHash": "a6d05824c24f34915fd1b47759c0000db6a47d6f893cf8ee18d406f006e28b80", | ||
"typeScriptVersion": "4.8" | ||
} |
@@ -11,3 +11,3 @@ # Installation | ||
### Additional Details | ||
* Last updated: Tue, 29 Oct 2024 17:02:26 GMT | ||
* Last updated: Thu, 31 Oct 2024 05:35:24 GMT | ||
* Dependencies: none | ||
@@ -14,0 +14,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1848617
41350
68