@types/node 18.19.61 → 18.19.62
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- node v18.19/README.md +1 -1
- node v18.19/events.d.ts +305 -79
- node v18.19/package.json +2 -2
node v18.19/README.md
CHANGED
|
@@ -8,7 +8,7 @@ This package contains type definitions for node (https://nodejs.org/).
|
|
|
8
8
|
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node/v18.
|
|
9
9
|
|
|
10
10
|
### Additional Details
|
|
11
|
-
* Last updated:
|
|
11
|
+
* Last updated: Thu, 31 Oct 2024 05:35:24 GMT
|
|
12
12
|
* Dependencies: [undici-types](https://npmjs.com/package/undici-types)
|
|
13
13
|
|
|
14
14
|
# Credits
|
node v18.19/events.d.ts
CHANGED
|
@@ -34,13 +34,12 @@
|
|
|
34
34
|
* ```
|
|
35
35
|
* @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/events.js)
|
|
36
36
|
*/
|
|
37
|
+
|
|
37
38
|
declare module "events" {
|
|
38
39
|
import { AsyncResource, AsyncResourceOptions } from "node:async_hooks";
|
|
39
|
-
|
|
40
40
|
// NOTE: This class is in the docs but is **not actually exported** by Node.
|
|
41
41
|
// If https://github.com/nodejs/node/issues/39903 gets resolved and Node
|
|
42
42
|
// actually starts exporting the class, uncomment below.
|
|
43
|
-
|
|
44
43
|
// import { EventListener, EventListenerObject } from '__dom-events';
|
|
45
44
|
// /** The NodeEventTarget is a Node.js-specific extension to EventTarget that emulates a subset of the EventEmitter API. */
|
|
46
45
|
// interface NodeEventTarget extends EventTarget {
|
|
@@ -71,7 +70,6 @@ declare module "events" {
|
|
|
71
70
|
// */
|
|
72
71
|
// removeListener(type: string, listener: EventListener | EventListenerObject): this;
|
|
73
72
|
// }
|
|
74
|
-
|
|
75
73
|
interface EventEmitterOptions {
|
|
76
74
|
/**
|
|
77
75
|
* Enables automatic capturing of promise rejection.
|
|
@@ -93,25 +91,33 @@ declare module "events" {
|
|
|
93
91
|
): any;
|
|
94
92
|
}
|
|
95
93
|
interface StaticEventEmitterOptions {
|
|
94
|
+
/**
|
|
95
|
+
* Can be used to cancel awaiting events.
|
|
96
|
+
*/
|
|
96
97
|
signal?: AbortSignal | undefined;
|
|
97
98
|
}
|
|
98
|
-
interface EventEmitter<
|
|
99
|
-
type EventMap<
|
|
100
|
-
type
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
99
|
+
interface EventEmitter<Events extends EventMap<Events> = {}> extends NodeJS.EventEmitter<Events> {}
|
|
100
|
+
type EventMap<Events> = Record<keyof Events, unknown[]>;
|
|
101
|
+
type Args<Events extends EventMap<Events>, EventName> = EventName extends keyof Events ? (
|
|
102
|
+
| Events[EventName]
|
|
103
|
+
| (EventName extends keyof EventEmitter.EventEmitterBuiltInEventMap
|
|
104
|
+
? EventEmitter.EventEmitterBuiltInEventMap[EventName]
|
|
105
|
+
: never)
|
|
106
|
+
)
|
|
107
|
+
: (EventName extends keyof EventEmitter.EventEmitterBuiltInEventMap
|
|
108
|
+
? EventEmitter.EventEmitterBuiltInEventMap[EventName]
|
|
109
|
+
: any[]);
|
|
110
|
+
type EventNames<Events extends EventMap<Events>> = {} extends Events ? (string | symbol)
|
|
111
|
+
: (keyof Events | keyof EventEmitter.EventEmitterBuiltInEventMap);
|
|
112
|
+
type Listener<Events extends EventMap<Events>, EventName> = EventName extends keyof Events ?
|
|
113
|
+
| ((...args: Events[EventName]) => void)
|
|
114
|
+
| (EventName extends keyof EventEmitter.EventEmitterBuiltInEventMap
|
|
115
|
+
? (...args: EventEmitter.EventEmitterBuiltInEventMap[EventName]) => void
|
|
116
|
+
: never)
|
|
117
|
+
: (EventName extends keyof EventEmitter.EventEmitterBuiltInEventMap
|
|
118
|
+
? (...args: EventEmitter.EventEmitterBuiltInEventMap[EventName]) => void
|
|
119
|
+
: (...args: any[]) => void);
|
|
120
|
+
|
|
115
121
|
/**
|
|
116
122
|
* The `EventEmitter` class is defined and exposed by the `events` module:
|
|
117
123
|
*
|
|
@@ -125,10 +131,20 @@ declare module "events" {
|
|
|
125
131
|
* It supports the following option:
|
|
126
132
|
* @since v0.1.26
|
|
127
133
|
*/
|
|
128
|
-
class EventEmitter<
|
|
134
|
+
class EventEmitter<Events extends EventMap<Events> = {}> {
|
|
129
135
|
constructor(options?: EventEmitterOptions);
|
|
130
136
|
|
|
131
|
-
|
|
137
|
+
// This "property" is used to brand a specific instance of the EventEmitter class with its Event map, which is needed
|
|
138
|
+
// in order to infer the map if we have a chain like `class A extends EventEmitter<{}>` (or many levels deep)
|
|
139
|
+
// It is also marked as possibly undefined in order to allow something like `const t: NodeJS.EventEmitter<{}> = { <insert implementation here> };`
|
|
140
|
+
readonly #internalTypeOnlyBrand?: Events;
|
|
141
|
+
|
|
142
|
+
[EventEmitter.captureRejectionSymbol]?<EventName extends EventNames<Events>>(
|
|
143
|
+
error: Error,
|
|
144
|
+
event: EventName,
|
|
145
|
+
...args: Args<Events, EventName>
|
|
146
|
+
): void;
|
|
147
|
+
[EventEmitter.captureRejectionSymbol]?(error: Error, event: string | symbol, ...args: any[]): void;
|
|
132
148
|
|
|
133
149
|
/**
|
|
134
150
|
* Creates a `Promise` that is fulfilled when the `EventEmitter` emits the given
|
|
@@ -212,6 +228,11 @@ declare module "events" {
|
|
|
212
228
|
* ```
|
|
213
229
|
* @since v11.13.0, v10.16.0
|
|
214
230
|
*/
|
|
231
|
+
static once<Events extends EventMap<Events>, EventName extends EventNames<Events>>(
|
|
232
|
+
emitter: EventEmitter<Events>,
|
|
233
|
+
eventName: EventName,
|
|
234
|
+
options?: StaticEventEmitterOptions,
|
|
235
|
+
): Promise<Args<Events, EventName>>;
|
|
215
236
|
static once(
|
|
216
237
|
emitter: _NodeEventTarget,
|
|
217
238
|
eventName: string | symbol,
|
|
@@ -273,16 +294,20 @@ declare module "events" {
|
|
|
273
294
|
* process.nextTick(() => ac.abort());
|
|
274
295
|
* ```
|
|
275
296
|
* @since v13.6.0, v12.16.0
|
|
276
|
-
* @
|
|
277
|
-
* @return that iterates `eventName` events emitted by the `emitter`
|
|
297
|
+
* @return An `AsyncIterator` that iterates `eventName` events emitted by the `emitter`
|
|
278
298
|
*/
|
|
299
|
+
static on<Events extends EventMap<Events>, EventName extends EventNames<Events>>(
|
|
300
|
+
emitter: EventEmitter<Events>,
|
|
301
|
+
eventName: EventName,
|
|
302
|
+
options?: StaticEventEmitterOptions,
|
|
303
|
+
): NodeJS.AsyncIterator<Args<Events, EventName>>;
|
|
279
304
|
static on(
|
|
280
305
|
emitter: NodeJS.EventEmitter,
|
|
281
|
-
eventName: string,
|
|
306
|
+
eventName: string | symbol,
|
|
282
307
|
options?: StaticEventEmitterOptions,
|
|
283
|
-
): NodeJS.AsyncIterator<any>;
|
|
308
|
+
): NodeJS.AsyncIterator<any[]>;
|
|
284
309
|
/**
|
|
285
|
-
* A class method that returns the number of listeners for the given `eventName`registered on the given `emitter`.
|
|
310
|
+
* A class method that returns the number of listeners for the given `eventName` registered on the given `emitter`.
|
|
286
311
|
*
|
|
287
312
|
* ```js
|
|
288
313
|
* import { EventEmitter, listenerCount } from 'node:events';
|
|
@@ -297,6 +322,27 @@ declare module "events" {
|
|
|
297
322
|
* @param emitter The emitter to query
|
|
298
323
|
* @param eventName The event name
|
|
299
324
|
*/
|
|
325
|
+
static listenerCount<Events extends EventMap<Events>, EventName extends EventNames<Events>>(
|
|
326
|
+
emitter: EventEmitter<Events>,
|
|
327
|
+
eventName: EventName,
|
|
328
|
+
): number;
|
|
329
|
+
/**
|
|
330
|
+
* A class method that returns the number of listeners for the given `eventName` registered on the given `emitter`.
|
|
331
|
+
*
|
|
332
|
+
* ```js
|
|
333
|
+
* const { EventEmitter, listenerCount } = require('events');
|
|
334
|
+
*
|
|
335
|
+
* const myEmitter = new EventEmitter();
|
|
336
|
+
* myEmitter.on('event', () => {});
|
|
337
|
+
* myEmitter.on('event', () => {});
|
|
338
|
+
* console.log(listenerCount(myEmitter, 'event'));
|
|
339
|
+
* // Prints: 2
|
|
340
|
+
* ```
|
|
341
|
+
* @since v0.9.12
|
|
342
|
+
* @deprecated Since v3.2.0 - Use `listenerCount` instead.
|
|
343
|
+
* @param emitter The emitter to query
|
|
344
|
+
* @param eventName The event name
|
|
345
|
+
*/
|
|
300
346
|
static listenerCount(emitter: NodeJS.EventEmitter, eventName: string | symbol): number;
|
|
301
347
|
/**
|
|
302
348
|
* Returns a copy of the array of listeners for the event named `eventName`.
|
|
@@ -314,17 +360,21 @@ declare module "events" {
|
|
|
314
360
|
* const ee = new EventEmitter();
|
|
315
361
|
* const listener = () => console.log('Events are fun');
|
|
316
362
|
* ee.on('foo', listener);
|
|
317
|
-
* getEventListeners(ee, 'foo'); // [listener]
|
|
363
|
+
* console.log(getEventListeners(ee, 'foo')); // [ [Function: listener] ]
|
|
318
364
|
* }
|
|
319
365
|
* {
|
|
320
366
|
* const et = new EventTarget();
|
|
321
367
|
* const listener = () => console.log('Events are fun');
|
|
322
368
|
* et.addEventListener('foo', listener);
|
|
323
|
-
* getEventListeners(et, 'foo'); // [listener]
|
|
369
|
+
* console.log(getEventListeners(et, 'foo')); // [ [Function: listener] ]
|
|
324
370
|
* }
|
|
325
371
|
* ```
|
|
326
372
|
* @since v15.2.0, v14.17.0
|
|
327
373
|
*/
|
|
374
|
+
static getEventListeners<Events extends EventMap<Events>, EventName extends EventNames<Events>>(
|
|
375
|
+
emitter: EventEmitter<Events>,
|
|
376
|
+
name: EventName,
|
|
377
|
+
): Array<Listener<Events, EventName>>;
|
|
328
378
|
static getEventListeners(emitter: _DOMEventTarget | NodeJS.EventEmitter, name: string | symbol): Function[];
|
|
329
379
|
/**
|
|
330
380
|
* Returns the currently set max amount of listeners.
|
|
@@ -337,7 +387,7 @@ declare module "events" {
|
|
|
337
387
|
* the max set, the EventTarget will print a warning.
|
|
338
388
|
*
|
|
339
389
|
* ```js
|
|
340
|
-
*
|
|
390
|
+
* const { getMaxListeners, setMaxListeners, EventEmitter } = require('events');
|
|
341
391
|
*
|
|
342
392
|
* {
|
|
343
393
|
* const ee = new EventEmitter();
|
|
@@ -389,7 +439,7 @@ declare module "events" {
|
|
|
389
439
|
* Returns a disposable so that it may be unsubscribed from more easily.
|
|
390
440
|
*
|
|
391
441
|
* ```js
|
|
392
|
-
*
|
|
442
|
+
* const { addAbortListener } = require('events');
|
|
393
443
|
*
|
|
394
444
|
* function example(signal) {
|
|
395
445
|
* let disposable;
|
|
@@ -418,12 +468,58 @@ declare module "events" {
|
|
|
418
468
|
* regular `'error'` listener is installed.
|
|
419
469
|
*/
|
|
420
470
|
static readonly errorMonitor: unique symbol;
|
|
471
|
+
/**
|
|
472
|
+
* Value: `Symbol.for('nodejs.rejection')`
|
|
473
|
+
*
|
|
474
|
+
* See how to write a custom `rejection handler`.
|
|
475
|
+
* @since v13.4.0, v12.16.0
|
|
476
|
+
*/
|
|
421
477
|
static readonly captureRejectionSymbol: unique symbol;
|
|
422
478
|
/**
|
|
423
|
-
*
|
|
479
|
+
* Value: [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
|
|
480
|
+
*
|
|
481
|
+
* Change the default `captureRejections` option on all new `EventEmitter` objects.
|
|
482
|
+
* @since v13.4.0, v12.16.0
|
|
424
483
|
*/
|
|
425
|
-
// TODO: These should be described using static getter/setter pairs:
|
|
426
484
|
static captureRejections: boolean;
|
|
485
|
+
/**
|
|
486
|
+
* By default, a maximum of `10` listeners can be registered for any single
|
|
487
|
+
* event. This limit can be changed for individual `EventEmitter` instances
|
|
488
|
+
* using the `emitter.setMaxListeners(n)` method. To change the default
|
|
489
|
+
* for _all_`EventEmitter` instances, the `events.defaultMaxListeners` property
|
|
490
|
+
* can be used. If this value is not a positive number, a `RangeError` is thrown.
|
|
491
|
+
*
|
|
492
|
+
* Take caution when setting the `events.defaultMaxListeners` because the
|
|
493
|
+
* change affects _all_ `EventEmitter` instances, including those created before
|
|
494
|
+
* the change is made. However, calling `emitter.setMaxListeners(n)` still has
|
|
495
|
+
* precedence over `events.defaultMaxListeners`.
|
|
496
|
+
*
|
|
497
|
+
* This is not a hard limit. The `EventEmitter` instance will allow
|
|
498
|
+
* more listeners to be added but will output a trace warning to stderr indicating
|
|
499
|
+
* that a "possible EventEmitter memory leak" has been detected. For any single
|
|
500
|
+
* `EventEmitter`, the `emitter.getMaxListeners()` and `emitter.setMaxListeners()` methods can be used to
|
|
501
|
+
* temporarily avoid this warning:
|
|
502
|
+
*
|
|
503
|
+
* ```js
|
|
504
|
+
* const EventEmitter = require('events');
|
|
505
|
+
* const emitter = new EventEmitter();
|
|
506
|
+
* emitter.setMaxListeners(emitter.getMaxListeners() + 1);
|
|
507
|
+
* emitter.once('event', () => {
|
|
508
|
+
* // do stuff
|
|
509
|
+
* emitter.setMaxListeners(Math.max(emitter.getMaxListeners() - 1, 0));
|
|
510
|
+
* });
|
|
511
|
+
* ```
|
|
512
|
+
*
|
|
513
|
+
* The `--trace-warnings` command-line flag can be used to display the
|
|
514
|
+
* stack trace for such warnings.
|
|
515
|
+
*
|
|
516
|
+
* The emitted warning can be inspected with `process.on('warning')` and will
|
|
517
|
+
* have the additional `emitter`, `type`, and `count` properties, referring to
|
|
518
|
+
* the event emitter instance, the event's name and the number of attached
|
|
519
|
+
* listeners, respectively.
|
|
520
|
+
* Its `name` property is set to `'MaxListenersExceededWarning'`.
|
|
521
|
+
* @since v0.11.2
|
|
522
|
+
*/
|
|
427
523
|
static defaultMaxListeners: number;
|
|
428
524
|
}
|
|
429
525
|
import internal = require("node:events");
|
|
@@ -451,13 +547,41 @@ declare module "events" {
|
|
|
451
547
|
}
|
|
452
548
|
|
|
453
549
|
/**
|
|
454
|
-
* Integrates `EventEmitter` with `AsyncResource` for `EventEmitter`s that
|
|
455
|
-
* manual async tracking. Specifically, all events emitted by instances
|
|
456
|
-
* `EventEmitterAsyncResource` will run within its async context
|
|
550
|
+
* Integrates `EventEmitter` with `AsyncResource` for `EventEmitter`s that
|
|
551
|
+
* require manual async tracking. Specifically, all events emitted by instances
|
|
552
|
+
* of `events.EventEmitterAsyncResource` will run within its `async context`.
|
|
553
|
+
*
|
|
554
|
+
* ```js
|
|
555
|
+
* const { EventEmitterAsyncResource, EventEmitter } = require('events');
|
|
556
|
+
* const { notStrictEqual, strictEqual } = require('assert');
|
|
557
|
+
* const { executionAsyncId, triggerAsyncId } = require('async_hooks');
|
|
558
|
+
*
|
|
559
|
+
* // Async tracking tooling will identify this as 'Q'.
|
|
560
|
+
* const ee1 = new EventEmitterAsyncResource({ name: 'Q' });
|
|
561
|
+
*
|
|
562
|
+
* // 'foo' listeners will run in the EventEmitters async context.
|
|
563
|
+
* ee1.on('foo', () => {
|
|
564
|
+
* strictEqual(executionAsyncId(), ee1.asyncId);
|
|
565
|
+
* strictEqual(triggerAsyncId(), ee1.triggerAsyncId);
|
|
566
|
+
* });
|
|
457
567
|
*
|
|
458
|
-
*
|
|
459
|
-
*
|
|
460
|
-
*
|
|
568
|
+
* const ee2 = new EventEmitter();
|
|
569
|
+
*
|
|
570
|
+
* // 'foo' listeners on ordinary EventEmitters that do not track async
|
|
571
|
+
* // context, however, run in the same async context as the emit().
|
|
572
|
+
* ee2.on('foo', () => {
|
|
573
|
+
* notStrictEqual(executionAsyncId(), ee2.asyncId);
|
|
574
|
+
* notStrictEqual(triggerAsyncId(), ee2.triggerAsyncId);
|
|
575
|
+
* });
|
|
576
|
+
*
|
|
577
|
+
* Promise.resolve().then(() => {
|
|
578
|
+
* ee1.emit('foo');
|
|
579
|
+
* ee2.emit('foo');
|
|
580
|
+
* });
|
|
581
|
+
* ```
|
|
582
|
+
*
|
|
583
|
+
* The `EventEmitterAsyncResource` class has the same methods and takes the
|
|
584
|
+
* same options as `EventEmitter` and `AsyncResource` themselves.
|
|
461
585
|
* @since v17.4.0, v16.14.0
|
|
462
586
|
*/
|
|
463
587
|
export class EventEmitterAsyncResource extends EventEmitter {
|
|
@@ -466,34 +590,62 @@ declare module "events" {
|
|
|
466
590
|
*/
|
|
467
591
|
constructor(options?: EventEmitterAsyncResourceOptions);
|
|
468
592
|
/**
|
|
469
|
-
* Call all destroy hooks. This should only ever be called once. An
|
|
470
|
-
*
|
|
471
|
-
*
|
|
472
|
-
*
|
|
593
|
+
* Call all `destroy` hooks. This should only ever be called once. An error will
|
|
594
|
+
* be thrown if it is called more than once. This **must** be manually called. If
|
|
595
|
+
* the resource is left to be collected by the GC then the `destroy` hooks will
|
|
596
|
+
* never be called.
|
|
473
597
|
*/
|
|
474
598
|
emitDestroy(): void;
|
|
475
|
-
/**
|
|
599
|
+
/**
|
|
600
|
+
* The unique `asyncId` assigned to the resource.
|
|
601
|
+
*/
|
|
476
602
|
readonly asyncId: number;
|
|
477
|
-
/**
|
|
603
|
+
/**
|
|
604
|
+
* The same triggerAsyncId that is passed to the AsyncResource constructor.
|
|
605
|
+
*/
|
|
478
606
|
readonly triggerAsyncId: number;
|
|
479
|
-
/**
|
|
607
|
+
/**
|
|
608
|
+
* The returned `AsyncResource` object has an additional `eventEmitter` property
|
|
609
|
+
* that provides a reference to this `EventEmitterAsyncResource`.
|
|
610
|
+
*/
|
|
480
611
|
readonly asyncResource: EventEmitterReferencingAsyncResource;
|
|
481
612
|
}
|
|
613
|
+
|
|
614
|
+
export interface EventEmitterBuiltInEventMap {
|
|
615
|
+
newListener: [eventName: string | symbol, listener: Function];
|
|
616
|
+
removeListener: [eventName: string | symbol, listener: Function];
|
|
617
|
+
}
|
|
482
618
|
}
|
|
483
619
|
global {
|
|
484
620
|
namespace NodeJS {
|
|
485
|
-
interface EventEmitter<
|
|
486
|
-
[EventEmitter.captureRejectionSymbol]?<
|
|
621
|
+
interface EventEmitter<Events extends EventMap<Events> = {}> {
|
|
622
|
+
[EventEmitter.captureRejectionSymbol]?<EventName extends EventNames<Events>>(
|
|
623
|
+
error: Error,
|
|
624
|
+
event: EventName,
|
|
625
|
+
...args: Args<Events, EventName>
|
|
626
|
+
): void;
|
|
627
|
+
[EventEmitter.captureRejectionSymbol]?<EventName extends string | symbol>(
|
|
628
|
+
error: Error,
|
|
629
|
+
event: EventName,
|
|
630
|
+
...args: Args<Events, EventName>
|
|
631
|
+
): void;
|
|
487
632
|
/**
|
|
488
633
|
* Alias for `emitter.on(eventName, listener)`.
|
|
489
634
|
* @since v0.1.26
|
|
490
635
|
*/
|
|
491
|
-
addListener<
|
|
636
|
+
addListener<EventName extends EventNames<Events>>(
|
|
637
|
+
eventName: EventName,
|
|
638
|
+
listener: Listener<Events, EventName>,
|
|
639
|
+
): this;
|
|
640
|
+
addListener<EventName extends string | symbol>(
|
|
641
|
+
eventName: EventName,
|
|
642
|
+
listener: Listener<Events, EventName>,
|
|
643
|
+
): this;
|
|
492
644
|
/**
|
|
493
|
-
* Adds the `listener` function to the end of the listeners array for the
|
|
494
|
-
*
|
|
495
|
-
*
|
|
496
|
-
* times.
|
|
645
|
+
* Adds the `listener` function to the end of the listeners array for the event
|
|
646
|
+
* named `eventName`. No checks are made to see if the `listener` has already
|
|
647
|
+
* been added. Multiple calls passing the same combination of `eventName` and
|
|
648
|
+
* `listener` will result in the `listener` being added, and called, multiple times.
|
|
497
649
|
*
|
|
498
650
|
* ```js
|
|
499
651
|
* server.on('connection', (stream) => {
|
|
@@ -503,10 +655,11 @@ declare module "events" {
|
|
|
503
655
|
*
|
|
504
656
|
* Returns a reference to the `EventEmitter`, so that calls can be chained.
|
|
505
657
|
*
|
|
506
|
-
* 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
|
|
658
|
+
* 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
|
|
507
659
|
* event listener to the beginning of the listeners array.
|
|
508
660
|
*
|
|
509
661
|
* ```js
|
|
662
|
+
* const EventEmitter = require('events');
|
|
510
663
|
* const myEE = new EventEmitter();
|
|
511
664
|
* myEE.on('foo', () => console.log('a'));
|
|
512
665
|
* myEE.prependListener('foo', () => console.log('b'));
|
|
@@ -519,9 +672,16 @@ declare module "events" {
|
|
|
519
672
|
* @param eventName The name of the event.
|
|
520
673
|
* @param listener The callback function
|
|
521
674
|
*/
|
|
522
|
-
on<
|
|
675
|
+
on<EventName extends EventNames<Events>>(
|
|
676
|
+
eventName: EventName,
|
|
677
|
+
listener: Listener<Events, EventName>,
|
|
678
|
+
): this;
|
|
679
|
+
on<EventName extends string | symbol>(
|
|
680
|
+
eventName: EventName,
|
|
681
|
+
listener: Listener<Events, EventName>,
|
|
682
|
+
): this;
|
|
523
683
|
/**
|
|
524
|
-
* Adds a **one-time
|
|
684
|
+
* Adds a **one-time** `listener` function for the event named `eventName`. The
|
|
525
685
|
* next time `eventName` is triggered, this listener is removed and then invoked.
|
|
526
686
|
*
|
|
527
687
|
* ```js
|
|
@@ -532,10 +692,11 @@ declare module "events" {
|
|
|
532
692
|
*
|
|
533
693
|
* Returns a reference to the `EventEmitter`, so that calls can be chained.
|
|
534
694
|
*
|
|
535
|
-
* 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
|
|
695
|
+
* 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
|
|
536
696
|
* event listener to the beginning of the listeners array.
|
|
537
697
|
*
|
|
538
698
|
* ```js
|
|
699
|
+
* const EventEmitter = require('events');
|
|
539
700
|
* const myEE = new EventEmitter();
|
|
540
701
|
* myEE.once('foo', () => console.log('a'));
|
|
541
702
|
* myEE.prependOnceListener('foo', () => console.log('b'));
|
|
@@ -548,9 +709,16 @@ declare module "events" {
|
|
|
548
709
|
* @param eventName The name of the event.
|
|
549
710
|
* @param listener The callback function
|
|
550
711
|
*/
|
|
551
|
-
once<
|
|
712
|
+
once<EventName extends EventNames<Events>>(
|
|
713
|
+
eventName: EventName,
|
|
714
|
+
listener: Listener<Events, EventName>,
|
|
715
|
+
): this;
|
|
716
|
+
once<EventName extends string | symbol>(
|
|
717
|
+
eventName: EventName,
|
|
718
|
+
listener: Listener<Events, EventName>,
|
|
719
|
+
): this;
|
|
552
720
|
/**
|
|
553
|
-
* Removes the specified `listener` from the listener array for the event named`eventName`.
|
|
721
|
+
* Removes the specified `listener` from the listener array for the event named `eventName`.
|
|
554
722
|
*
|
|
555
723
|
* ```js
|
|
556
724
|
* const callback = (stream) => {
|
|
@@ -567,10 +735,12 @@ declare module "events" {
|
|
|
567
735
|
* called multiple times to remove each instance.
|
|
568
736
|
*
|
|
569
737
|
* Once an event is emitted, all listeners attached to it at the
|
|
570
|
-
* time of emitting are called in order. This implies that any`removeListener()` or `removeAllListeners()` calls _after_ emitting and _before_ the last listener finishes execution
|
|
738
|
+
* time of emitting are called in order. This implies that any `removeListener()` or `removeAllListeners()` calls _after_ emitting and _before_ the last listener finishes execution
|
|
571
739
|
* will not remove them from`emit()` in progress. Subsequent events behave as expected.
|
|
572
740
|
*
|
|
573
741
|
* ```js
|
|
742
|
+
* const EventEmitter = require('events');
|
|
743
|
+
* class MyEmitter extends EventEmitter {}
|
|
574
744
|
* const myEmitter = new MyEmitter();
|
|
575
745
|
*
|
|
576
746
|
* const callbackA = () => {
|
|
@@ -608,9 +778,10 @@ declare module "events" {
|
|
|
608
778
|
*
|
|
609
779
|
* When a single function has been added as a handler multiple times for a single
|
|
610
780
|
* event (as in the example below), `removeListener()` will remove the most
|
|
611
|
-
* recently added instance. In the example the `once('ping')`listener is removed:
|
|
781
|
+
* recently added instance. In the example the `once('ping')` listener is removed:
|
|
612
782
|
*
|
|
613
783
|
* ```js
|
|
784
|
+
* const EventEmitter = require('events');
|
|
614
785
|
* const ee = new EventEmitter();
|
|
615
786
|
*
|
|
616
787
|
* function pong() {
|
|
@@ -628,12 +799,26 @@ declare module "events" {
|
|
|
628
799
|
* Returns a reference to the `EventEmitter`, so that calls can be chained.
|
|
629
800
|
* @since v0.1.26
|
|
630
801
|
*/
|
|
631
|
-
removeListener<
|
|
802
|
+
removeListener<EventName extends EventNames<Events>>(
|
|
803
|
+
eventName: EventName,
|
|
804
|
+
listener: Listener<Events, EventName>,
|
|
805
|
+
): this;
|
|
806
|
+
removeListener<EventName extends string | symbol>(
|
|
807
|
+
eventName: EventName,
|
|
808
|
+
listener: Listener<Events, EventName>,
|
|
809
|
+
): this;
|
|
632
810
|
/**
|
|
633
811
|
* Alias for `emitter.removeListener()`.
|
|
634
812
|
* @since v10.0.0
|
|
635
813
|
*/
|
|
636
|
-
off<
|
|
814
|
+
off<EventName extends EventNames<Events>>(
|
|
815
|
+
eventName: EventName,
|
|
816
|
+
listener: Listener<Events, EventName>,
|
|
817
|
+
): this;
|
|
818
|
+
off<EventName extends string | symbol>(
|
|
819
|
+
eventName: EventName,
|
|
820
|
+
listener: Listener<Events, EventName>,
|
|
821
|
+
): this;
|
|
637
822
|
/**
|
|
638
823
|
* Removes all listeners, or those of the specified `eventName`.
|
|
639
824
|
*
|
|
@@ -644,12 +829,15 @@ declare module "events" {
|
|
|
644
829
|
* Returns a reference to the `EventEmitter`, so that calls can be chained.
|
|
645
830
|
* @since v0.1.26
|
|
646
831
|
*/
|
|
647
|
-
|
|
832
|
+
/* eslint-disable @definitelytyped/no-unnecessary-generics */
|
|
833
|
+
removeAllListeners<EventName extends EventNames<Events>>(eventName: EventName): this;
|
|
834
|
+
removeAllListeners<EventName extends string | symbol>(eventName?: EventName): this;
|
|
835
|
+
/* eslint-enable @definitelytyped/no-unnecessary-generics */
|
|
648
836
|
/**
|
|
649
837
|
* By default `EventEmitter`s will print a warning if more than `10` listeners are
|
|
650
838
|
* added for a particular event. This is a useful default that helps finding
|
|
651
839
|
* memory leaks. The `emitter.setMaxListeners()` method allows the limit to be
|
|
652
|
-
* modified for this specific `EventEmitter` instance. The value can be set to`Infinity` (or `0`) to indicate an unlimited number of listeners.
|
|
840
|
+
* modified for this specific `EventEmitter` instance. The value can be set to `Infinity` (or `0`) to indicate an unlimited number of listeners.
|
|
653
841
|
*
|
|
654
842
|
* Returns a reference to the `EventEmitter`, so that calls can be chained.
|
|
655
843
|
* @since v0.3.5
|
|
@@ -673,12 +861,18 @@ declare module "events" {
|
|
|
673
861
|
* ```
|
|
674
862
|
* @since v0.1.26
|
|
675
863
|
*/
|
|
676
|
-
listeners<
|
|
864
|
+
listeners<EventName extends EventNames<Events>>(
|
|
865
|
+
eventName: EventName,
|
|
866
|
+
): Array<Listener<Events, EventName>>;
|
|
867
|
+
listeners<EventName extends string | symbol>(
|
|
868
|
+
eventName: EventName,
|
|
869
|
+
): Array<Listener<Events, EventName>>;
|
|
677
870
|
/**
|
|
678
871
|
* Returns a copy of the array of listeners for the event named `eventName`,
|
|
679
872
|
* including any wrappers (such as those created by `.once()`).
|
|
680
873
|
*
|
|
681
874
|
* ```js
|
|
875
|
+
* const EventEmitter = require('events');
|
|
682
876
|
* const emitter = new EventEmitter();
|
|
683
877
|
* emitter.once('log', () => console.log('log once'));
|
|
684
878
|
*
|
|
@@ -703,9 +897,14 @@ declare module "events" {
|
|
|
703
897
|
* ```
|
|
704
898
|
* @since v9.4.0
|
|
705
899
|
*/
|
|
706
|
-
rawListeners<
|
|
900
|
+
rawListeners<EventName extends EventNames<Events>>(
|
|
901
|
+
eventName: EventName,
|
|
902
|
+
): Array<Listener<Events, EventName>>;
|
|
903
|
+
rawListeners<EventName extends string | symbol>(
|
|
904
|
+
eventName: EventName,
|
|
905
|
+
): Array<Listener<Events, EventName>>;
|
|
707
906
|
/**
|
|
708
|
-
* Synchronously calls each of the listeners registered for the event named`eventName`, in the order they were registered, passing the supplied arguments
|
|
907
|
+
* Synchronously calls each of the listeners registered for the event named `eventName`, in the order they were registered, passing the supplied arguments
|
|
709
908
|
* to each.
|
|
710
909
|
*
|
|
711
910
|
* Returns `true` if the event had listeners, `false` otherwise.
|
|
@@ -744,22 +943,35 @@ declare module "events" {
|
|
|
744
943
|
* ```
|
|
745
944
|
* @since v0.1.26
|
|
746
945
|
*/
|
|
747
|
-
emit<
|
|
946
|
+
emit<EventName extends EventNames<Events>>(
|
|
947
|
+
eventName: EventName,
|
|
948
|
+
...args: Args<Events, EventName>
|
|
949
|
+
): boolean;
|
|
950
|
+
emit<EventName extends string | symbol>(
|
|
951
|
+
eventName: EventName,
|
|
952
|
+
...args: Args<Events, EventName>
|
|
953
|
+
): boolean;
|
|
748
954
|
/**
|
|
749
|
-
* Returns the number of listeners listening
|
|
750
|
-
*
|
|
751
|
-
*
|
|
752
|
-
* is found in the list of the listeners of the event.
|
|
955
|
+
* Returns the number of listeners listening for the event named `eventName`.
|
|
956
|
+
* If `listener` is provided, it will return how many times the listener is found
|
|
957
|
+
* in the list of the listeners of the event.
|
|
753
958
|
* @since v3.2.0
|
|
754
959
|
* @param eventName The name of the event being listened for
|
|
755
960
|
* @param listener The event handler function
|
|
756
961
|
*/
|
|
757
|
-
listenerCount<
|
|
962
|
+
listenerCount<EventName extends EventNames<Events>>(
|
|
963
|
+
eventName: EventName,
|
|
964
|
+
listener?: Listener<Events, EventName>,
|
|
965
|
+
): number;
|
|
966
|
+
listenerCount<EventName extends string | symbol>(
|
|
967
|
+
eventName: EventName,
|
|
968
|
+
listener?: Listener<Events, EventName>,
|
|
969
|
+
): number;
|
|
758
970
|
/**
|
|
759
971
|
* Adds the `listener` function to the _beginning_ of the listeners array for the
|
|
760
972
|
* event named `eventName`. No checks are made to see if the `listener` has
|
|
761
|
-
* already been added. Multiple calls passing the same combination of `eventName`
|
|
762
|
-
* times.
|
|
973
|
+
* already been added. Multiple calls passing the same combination of `eventName`
|
|
974
|
+
* and `listener` will result in the `listener` being added, and called, multiple times.
|
|
763
975
|
*
|
|
764
976
|
* ```js
|
|
765
977
|
* server.prependListener('connection', (stream) => {
|
|
@@ -772,7 +984,14 @@ declare module "events" {
|
|
|
772
984
|
* @param eventName The name of the event.
|
|
773
985
|
* @param listener The callback function
|
|
774
986
|
*/
|
|
775
|
-
prependListener<
|
|
987
|
+
prependListener<EventName extends EventNames<Events>>(
|
|
988
|
+
eventName: EventName,
|
|
989
|
+
listener: Listener<Events, EventName>,
|
|
990
|
+
): this;
|
|
991
|
+
prependListener<EventName extends string | symbol>(
|
|
992
|
+
eventName: EventName,
|
|
993
|
+
listener: Listener<Events, EventName>,
|
|
994
|
+
): this;
|
|
776
995
|
/**
|
|
777
996
|
* 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
|
|
778
997
|
* listener is removed, and then invoked.
|
|
@@ -788,7 +1007,14 @@ declare module "events" {
|
|
|
788
1007
|
* @param eventName The name of the event.
|
|
789
1008
|
* @param listener The callback function
|
|
790
1009
|
*/
|
|
791
|
-
prependOnceListener<
|
|
1010
|
+
prependOnceListener<EventName extends EventNames<Events>>(
|
|
1011
|
+
eventName: EventName,
|
|
1012
|
+
listener: Listener<Events, EventName>,
|
|
1013
|
+
): this;
|
|
1014
|
+
prependOnceListener<EventName extends string | symbol>(
|
|
1015
|
+
eventName: EventName,
|
|
1016
|
+
listener: Listener<Events, EventName>,
|
|
1017
|
+
): this;
|
|
792
1018
|
/**
|
|
793
1019
|
* Returns an array listing the events for which the emitter has registered
|
|
794
1020
|
* listeners. The values in the array are strings or `Symbol`s.
|
|
@@ -807,7 +1033,7 @@ declare module "events" {
|
|
|
807
1033
|
* ```
|
|
808
1034
|
* @since v6.0.0
|
|
809
1035
|
*/
|
|
810
|
-
eventNames(): Array<(string | symbol) &
|
|
1036
|
+
eventNames(): Array<(string | symbol)> & Array<EventNames<Events>>;
|
|
811
1037
|
}
|
|
812
1038
|
}
|
|
813
1039
|
}
|
node v18.19/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@types/node",
|
|
3
|
-
"version": "18.19.
|
|
3
|
+
"version": "18.19.62",
|
|
4
4
|
"description": "TypeScript definitions for node",
|
|
5
5
|
"homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node",
|
|
6
6
|
"license": "MIT",
|
|
@@ -225,6 +225,6 @@
|
|
|
225
225
|
"undici-types": "~5.26.4"
|
|
226
226
|
},
|
|
227
227
|
"peerDependencies": {},
|
|
228
|
-
"typesPublisherContentHash": "
|
|
228
|
+
"typesPublisherContentHash": "ea7c345bb61cffb74ee7ae872691ac155874e1506181f10dfd5d6f51a142ca34",
|
|
229
229
|
"typeScriptVersion": "4.8"
|
|
230
230
|
}
|