@types/node 16.18.117 → 16.18.118
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 v16.18/README.md +1 -1
- node v16.18/events.d.ts +81 -312
- node v16.18/package.json +2 -2
node v16.18/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/v16.
|
|
9
9
|
|
|
10
10
|
### Additional Details
|
|
11
|
-
* Last updated: Thu, 31 Oct 2024
|
|
11
|
+
* Last updated: Thu, 31 Oct 2024 18:02:52 GMT
|
|
12
12
|
* Dependencies: none
|
|
13
13
|
|
|
14
14
|
# Credits
|
node v16.18/events.d.ts
CHANGED
|
@@ -34,7 +34,6 @@
|
|
|
34
34
|
* ```
|
|
35
35
|
* @see [source](https://github.com/nodejs/node/blob/v16.9.0/lib/events.js)
|
|
36
36
|
*/
|
|
37
|
-
|
|
38
37
|
declare module "events" {
|
|
39
38
|
import { AsyncResource, AsyncResourceOptions } from "node:async_hooks";
|
|
40
39
|
|
|
@@ -57,33 +56,25 @@ declare module "events" {
|
|
|
57
56
|
): any;
|
|
58
57
|
}
|
|
59
58
|
interface StaticEventEmitterOptions {
|
|
60
|
-
/**
|
|
61
|
-
* Can be used to cancel awaiting events.
|
|
62
|
-
*/
|
|
63
59
|
signal?: AbortSignal | undefined;
|
|
64
60
|
}
|
|
65
|
-
interface EventEmitter<
|
|
66
|
-
type EventMap<
|
|
67
|
-
type
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
: never)
|
|
83
|
-
: (EventName extends keyof EventEmitter.EventEmitterBuiltInEventMap
|
|
84
|
-
? (...args: EventEmitter.EventEmitterBuiltInEventMap[EventName]) => void
|
|
85
|
-
: (...args: any[]) => void);
|
|
86
|
-
|
|
61
|
+
interface EventEmitter<T extends EventMap<T> = DefaultEventMap> extends NodeJS.EventEmitter<T> {}
|
|
62
|
+
type EventMap<T> = Record<keyof T, any[]> | DefaultEventMap;
|
|
63
|
+
type DefaultEventMap = [never];
|
|
64
|
+
type AnyRest = [...args: any[]];
|
|
65
|
+
type Args<K, T> = T extends DefaultEventMap ? AnyRest : (
|
|
66
|
+
K extends keyof T ? T[K] : never
|
|
67
|
+
);
|
|
68
|
+
type Key<K, T> = T extends DefaultEventMap ? string | symbol : K | keyof T;
|
|
69
|
+
type Key2<K, T> = T extends DefaultEventMap ? string | symbol : K & keyof T;
|
|
70
|
+
type Listener<K, T, F> = T extends DefaultEventMap ? F : (
|
|
71
|
+
K extends keyof T ? (
|
|
72
|
+
T[K] extends unknown[] ? (...args: T[K]) => void : never
|
|
73
|
+
)
|
|
74
|
+
: never
|
|
75
|
+
);
|
|
76
|
+
type Listener1<K, T> = Listener<K, T, (...args: any[]) => void>;
|
|
77
|
+
type Listener2<K, T> = Listener<K, T, Function>;
|
|
87
78
|
/**
|
|
88
79
|
* The `EventEmitter` class is defined and exposed by the `events` module:
|
|
89
80
|
*
|
|
@@ -97,20 +88,10 @@ declare module "events" {
|
|
|
97
88
|
* It supports the following option:
|
|
98
89
|
* @since v0.1.26
|
|
99
90
|
*/
|
|
100
|
-
class EventEmitter<
|
|
91
|
+
class EventEmitter<T extends EventMap<T> = DefaultEventMap> {
|
|
101
92
|
constructor(options?: EventEmitterOptions);
|
|
102
93
|
|
|
103
|
-
|
|
104
|
-
// in order to infer the map if we have a chain like `class A extends EventEmitter<{}>` (or many levels deep)
|
|
105
|
-
// It is also marked as possibly undefined in order to allow something like `const t: NodeJS.EventEmitter<{}> = { <insert implementation here> };`
|
|
106
|
-
readonly #internalTypeOnlyBrand?: Events;
|
|
107
|
-
|
|
108
|
-
[EventEmitter.captureRejectionSymbol]?<EventName extends EventNames<Events>>(
|
|
109
|
-
error: Error,
|
|
110
|
-
event: EventName,
|
|
111
|
-
...args: Args<Events, EventName>
|
|
112
|
-
): void;
|
|
113
|
-
[EventEmitter.captureRejectionSymbol]?(error: Error, event: string | symbol, ...args: any[]): void;
|
|
94
|
+
[EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: Key<K, T>, ...args: Args<K, T>): void;
|
|
114
95
|
|
|
115
96
|
/**
|
|
116
97
|
* Creates a `Promise` that is fulfilled when the `EventEmitter` emits the given
|
|
@@ -149,7 +130,7 @@ declare module "events" {
|
|
|
149
130
|
* run();
|
|
150
131
|
* ```
|
|
151
132
|
*
|
|
152
|
-
* The special handling of the `'error'` event is only used when `events.once()`
|
|
133
|
+
* 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
|
|
153
134
|
* '`error'` event itself, then it is treated as any other kind of event without
|
|
154
135
|
* special handling:
|
|
155
136
|
*
|
|
@@ -160,7 +141,7 @@ declare module "events" {
|
|
|
160
141
|
*
|
|
161
142
|
* once(ee, 'error')
|
|
162
143
|
* .then(([err]) => console.log('ok', err.message))
|
|
163
|
-
* .catch((err) => console.
|
|
144
|
+
* .catch((err) => console.log('error', err.message));
|
|
164
145
|
*
|
|
165
146
|
* ee.emit('error', new Error('boom'));
|
|
166
147
|
*
|
|
@@ -194,11 +175,6 @@ declare module "events" {
|
|
|
194
175
|
* ```
|
|
195
176
|
* @since v11.13.0, v10.16.0
|
|
196
177
|
*/
|
|
197
|
-
static once<Events extends EventMap<Events>, EventName extends EventNames<Events>>(
|
|
198
|
-
emitter: EventEmitter<Events>,
|
|
199
|
-
eventName: EventName,
|
|
200
|
-
options?: StaticEventEmitterOptions,
|
|
201
|
-
): Promise<Args<Events, EventName>>;
|
|
202
178
|
static once(
|
|
203
179
|
emitter: NodeEventTarget,
|
|
204
180
|
eventName: string | symbol,
|
|
@@ -260,20 +236,16 @@ declare module "events" {
|
|
|
260
236
|
* process.nextTick(() => ac.abort());
|
|
261
237
|
* ```
|
|
262
238
|
* @since v13.6.0, v12.16.0
|
|
263
|
-
* @
|
|
239
|
+
* @param eventName The name of the event being listened for
|
|
240
|
+
* @return that iterates `eventName` events emitted by the `emitter`
|
|
264
241
|
*/
|
|
265
|
-
static on<Events extends EventMap<Events>, EventName extends EventNames<Events>>(
|
|
266
|
-
emitter: EventEmitter<Events>,
|
|
267
|
-
eventName: EventName,
|
|
268
|
-
options?: StaticEventEmitterOptions,
|
|
269
|
-
): NodeJS.AsyncIterator<Args<Events, EventName>>;
|
|
270
242
|
static on(
|
|
271
243
|
emitter: NodeJS.EventEmitter,
|
|
272
|
-
eventName: string
|
|
244
|
+
eventName: string,
|
|
273
245
|
options?: StaticEventEmitterOptions,
|
|
274
|
-
): NodeJS.AsyncIterator<any
|
|
246
|
+
): NodeJS.AsyncIterator<any>;
|
|
275
247
|
/**
|
|
276
|
-
* A class method that returns the number of listeners for the given `eventName`
|
|
248
|
+
* A class method that returns the number of listeners for the given `eventName`registered on the given `emitter`.
|
|
277
249
|
*
|
|
278
250
|
* ```js
|
|
279
251
|
* import { EventEmitter, listenerCount } from 'node:events';
|
|
@@ -288,27 +260,6 @@ declare module "events" {
|
|
|
288
260
|
* @param emitter The emitter to query
|
|
289
261
|
* @param eventName The event name
|
|
290
262
|
*/
|
|
291
|
-
static listenerCount<Events extends EventMap<Events>, EventName extends EventNames<Events>>(
|
|
292
|
-
emitter: EventEmitter<Events>,
|
|
293
|
-
eventName: EventName,
|
|
294
|
-
): number;
|
|
295
|
-
/**
|
|
296
|
-
* A class method that returns the number of listeners for the given `eventName` registered on the given `emitter`.
|
|
297
|
-
*
|
|
298
|
-
* ```js
|
|
299
|
-
* const { EventEmitter, listenerCount } = require('events');
|
|
300
|
-
*
|
|
301
|
-
* const myEmitter = new EventEmitter();
|
|
302
|
-
* myEmitter.on('event', () => {});
|
|
303
|
-
* myEmitter.on('event', () => {});
|
|
304
|
-
* console.log(listenerCount(myEmitter, 'event'));
|
|
305
|
-
* // Prints: 2
|
|
306
|
-
* ```
|
|
307
|
-
* @since v0.9.12
|
|
308
|
-
* @deprecated Since v3.2.0 - Use `listenerCount` instead.
|
|
309
|
-
* @param emitter The emitter to query
|
|
310
|
-
* @param eventName The event name
|
|
311
|
-
*/
|
|
312
263
|
static listenerCount(emitter: NodeJS.EventEmitter, eventName: string | symbol): number;
|
|
313
264
|
/**
|
|
314
265
|
* Returns a copy of the array of listeners for the event named `eventName`.
|
|
@@ -326,21 +277,17 @@ declare module "events" {
|
|
|
326
277
|
* const ee = new EventEmitter();
|
|
327
278
|
* const listener = () => console.log('Events are fun');
|
|
328
279
|
* ee.on('foo', listener);
|
|
329
|
-
*
|
|
280
|
+
* getEventListeners(ee, 'foo'); // [listener]
|
|
330
281
|
* }
|
|
331
282
|
* {
|
|
332
283
|
* const et = new EventTarget();
|
|
333
284
|
* const listener = () => console.log('Events are fun');
|
|
334
285
|
* et.addEventListener('foo', listener);
|
|
335
|
-
*
|
|
286
|
+
* getEventListeners(et, 'foo'); // [listener]
|
|
336
287
|
* }
|
|
337
288
|
* ```
|
|
338
|
-
* @since v15.2.0
|
|
289
|
+
* @since v15.2.0
|
|
339
290
|
*/
|
|
340
|
-
static getEventListeners<Events extends EventMap<Events>, EventName extends EventNames<Events>>(
|
|
341
|
-
emitter: EventEmitter<Events>,
|
|
342
|
-
name: EventName,
|
|
343
|
-
): Array<Listener<Events, EventName>>;
|
|
344
291
|
static getEventListeners(emitter: DOMEventTarget | NodeJS.EventEmitter, name: string | symbol): Function[];
|
|
345
292
|
/**
|
|
346
293
|
* ```js
|
|
@@ -361,65 +308,21 @@ declare module "events" {
|
|
|
361
308
|
*/
|
|
362
309
|
static setMaxListeners(n?: number, ...eventTargets: Array<DOMEventTarget | NodeJS.EventEmitter>): void;
|
|
363
310
|
/**
|
|
364
|
-
* This symbol shall be used to install a listener for only monitoring `'error'`
|
|
311
|
+
* This symbol shall be used to install a listener for only monitoring `'error'`
|
|
312
|
+
* events. Listeners installed using this symbol are called before the regular
|
|
313
|
+
* `'error'` listeners are called.
|
|
365
314
|
*
|
|
366
|
-
* Installing a listener using this symbol does not change the behavior once an
|
|
315
|
+
* Installing a listener using this symbol does not change the behavior once an
|
|
316
|
+
* `'error'` event is emitted, therefore the process will still crash if no
|
|
367
317
|
* regular `'error'` listener is installed.
|
|
368
|
-
* @since v13.6.0, v12.17.0
|
|
369
318
|
*/
|
|
370
319
|
static readonly errorMonitor: unique symbol;
|
|
371
|
-
/**
|
|
372
|
-
* Value: `Symbol.for('nodejs.rejection')`
|
|
373
|
-
*
|
|
374
|
-
* See how to write a custom `rejection handler`.
|
|
375
|
-
* @since v13.4.0, v12.16.0
|
|
376
|
-
*/
|
|
377
320
|
static readonly captureRejectionSymbol: unique symbol;
|
|
378
321
|
/**
|
|
379
|
-
*
|
|
380
|
-
*
|
|
381
|
-
* Change the default `captureRejections` option on all new `EventEmitter` objects.
|
|
382
|
-
* @since v13.4.0, v12.16.0
|
|
322
|
+
* Sets or gets the default captureRejection value for all emitters.
|
|
383
323
|
*/
|
|
324
|
+
// TODO: These should be described using static getter/setter pairs:
|
|
384
325
|
static captureRejections: boolean;
|
|
385
|
-
/**
|
|
386
|
-
* By default, a maximum of `10` listeners can be registered for any single
|
|
387
|
-
* event. This limit can be changed for individual `EventEmitter` instances
|
|
388
|
-
* using the `emitter.setMaxListeners(n)` method. To change the default
|
|
389
|
-
* for _all_`EventEmitter` instances, the `events.defaultMaxListeners` property
|
|
390
|
-
* can be used. If this value is not a positive number, a `RangeError` is thrown.
|
|
391
|
-
*
|
|
392
|
-
* Take caution when setting the `events.defaultMaxListeners` because the
|
|
393
|
-
* change affects _all_ `EventEmitter` instances, including those created before
|
|
394
|
-
* the change is made. However, calling `emitter.setMaxListeners(n)` still has
|
|
395
|
-
* precedence over `events.defaultMaxListeners`.
|
|
396
|
-
*
|
|
397
|
-
* This is not a hard limit. The `EventEmitter` instance will allow
|
|
398
|
-
* more listeners to be added but will output a trace warning to stderr indicating
|
|
399
|
-
* that a "possible EventEmitter memory leak" has been detected. For any single
|
|
400
|
-
* `EventEmitter`, the `emitter.getMaxListeners()` and `emitter.setMaxListeners()` methods can be used to
|
|
401
|
-
* temporarily avoid this warning:
|
|
402
|
-
*
|
|
403
|
-
* ```js
|
|
404
|
-
* const EventEmitter = require('events');
|
|
405
|
-
* const emitter = new EventEmitter();
|
|
406
|
-
* emitter.setMaxListeners(emitter.getMaxListeners() + 1);
|
|
407
|
-
* emitter.once('event', () => {
|
|
408
|
-
* // do stuff
|
|
409
|
-
* emitter.setMaxListeners(Math.max(emitter.getMaxListeners() - 1, 0));
|
|
410
|
-
* });
|
|
411
|
-
* ```
|
|
412
|
-
*
|
|
413
|
-
* The `--trace-warnings` command-line flag can be used to display the
|
|
414
|
-
* stack trace for such warnings.
|
|
415
|
-
*
|
|
416
|
-
* The emitted warning can be inspected with `process.on('warning')` and will
|
|
417
|
-
* have the additional `emitter`, `type`, and `count` properties, referring to
|
|
418
|
-
* the event emitter instance, the event's name and the number of attached
|
|
419
|
-
* listeners, respectively.
|
|
420
|
-
* Its `name` property is set to `'MaxListenersExceededWarning'`.
|
|
421
|
-
* @since v0.11.2
|
|
422
|
-
*/
|
|
423
326
|
static defaultMaxListeners: number;
|
|
424
327
|
}
|
|
425
328
|
import internal = require("node:events");
|
|
@@ -447,41 +350,13 @@ declare module "events" {
|
|
|
447
350
|
}
|
|
448
351
|
|
|
449
352
|
/**
|
|
450
|
-
* Integrates `EventEmitter` with `AsyncResource` for `EventEmitter`s that
|
|
451
|
-
*
|
|
452
|
-
*
|
|
353
|
+
* Integrates `EventEmitter` with `AsyncResource` for `EventEmitter`s that require
|
|
354
|
+
* manual async tracking. Specifically, all events emitted by instances of
|
|
355
|
+
* `EventEmitterAsyncResource` will run within its async context.
|
|
453
356
|
*
|
|
454
|
-
*
|
|
455
|
-
*
|
|
456
|
-
*
|
|
457
|
-
* const { executionAsyncId, triggerAsyncId } = require('async_hooks');
|
|
458
|
-
*
|
|
459
|
-
* // Async tracking tooling will identify this as 'Q'.
|
|
460
|
-
* const ee1 = new EventEmitterAsyncResource({ name: 'Q' });
|
|
461
|
-
*
|
|
462
|
-
* // 'foo' listeners will run in the EventEmitters async context.
|
|
463
|
-
* ee1.on('foo', () => {
|
|
464
|
-
* strictEqual(executionAsyncId(), ee1.asyncId);
|
|
465
|
-
* strictEqual(triggerAsyncId(), ee1.triggerAsyncId);
|
|
466
|
-
* });
|
|
467
|
-
*
|
|
468
|
-
* const ee2 = new EventEmitter();
|
|
469
|
-
*
|
|
470
|
-
* // 'foo' listeners on ordinary EventEmitters that do not track async
|
|
471
|
-
* // context, however, run in the same async context as the emit().
|
|
472
|
-
* ee2.on('foo', () => {
|
|
473
|
-
* notStrictEqual(executionAsyncId(), ee2.asyncId);
|
|
474
|
-
* notStrictEqual(triggerAsyncId(), ee2.triggerAsyncId);
|
|
475
|
-
* });
|
|
476
|
-
*
|
|
477
|
-
* Promise.resolve().then(() => {
|
|
478
|
-
* ee1.emit('foo');
|
|
479
|
-
* ee2.emit('foo');
|
|
480
|
-
* });
|
|
481
|
-
* ```
|
|
482
|
-
*
|
|
483
|
-
* The `EventEmitterAsyncResource` class has the same methods and takes the
|
|
484
|
-
* same options as `EventEmitter` and `AsyncResource` themselves.
|
|
357
|
+
* The EventEmitterAsyncResource class has the same methods and takes the
|
|
358
|
+
* same options as EventEmitter and AsyncResource themselves.
|
|
359
|
+
* @throws if `options.name` is not provided when instantiated directly.
|
|
485
360
|
* @since v17.4.0, v16.14.0
|
|
486
361
|
*/
|
|
487
362
|
export class EventEmitterAsyncResource extends EventEmitter {
|
|
@@ -490,62 +365,34 @@ declare module "events" {
|
|
|
490
365
|
*/
|
|
491
366
|
constructor(options?: EventEmitterAsyncResourceOptions);
|
|
492
367
|
/**
|
|
493
|
-
* Call all
|
|
494
|
-
* be thrown if it is called more than once. This
|
|
495
|
-
* the resource is left to be collected by the GC then
|
|
496
|
-
* never be called.
|
|
368
|
+
* Call all destroy hooks. This should only ever be called once. An
|
|
369
|
+
* error will be thrown if it is called more than once. This must be
|
|
370
|
+
* manually called. If the resource is left to be collected by the GC then
|
|
371
|
+
* the destroy hooks will never be called.
|
|
497
372
|
*/
|
|
498
373
|
emitDestroy(): void;
|
|
499
|
-
/**
|
|
500
|
-
* The unique `asyncId` assigned to the resource.
|
|
501
|
-
*/
|
|
374
|
+
/** The unique asyncId assigned to the resource. */
|
|
502
375
|
readonly asyncId: number;
|
|
503
|
-
/**
|
|
504
|
-
* The same triggerAsyncId that is passed to the AsyncResource constructor.
|
|
505
|
-
*/
|
|
376
|
+
/** The same triggerAsyncId that is passed to the AsyncResource constructor. */
|
|
506
377
|
readonly triggerAsyncId: number;
|
|
507
|
-
/**
|
|
508
|
-
* The returned `AsyncResource` object has an additional `eventEmitter` property
|
|
509
|
-
* that provides a reference to this `EventEmitterAsyncResource`.
|
|
510
|
-
*/
|
|
378
|
+
/** The underlying AsyncResource */
|
|
511
379
|
readonly asyncResource: EventEmitterReferencingAsyncResource;
|
|
512
380
|
}
|
|
513
|
-
|
|
514
|
-
export interface EventEmitterBuiltInEventMap {
|
|
515
|
-
newListener: [eventName: string | symbol, listener: Function];
|
|
516
|
-
removeListener: [eventName: string | symbol, listener: Function];
|
|
517
|
-
}
|
|
518
381
|
}
|
|
519
382
|
global {
|
|
520
383
|
namespace NodeJS {
|
|
521
|
-
interface EventEmitter<
|
|
522
|
-
[EventEmitter.captureRejectionSymbol]?<
|
|
523
|
-
error: Error,
|
|
524
|
-
event: EventName,
|
|
525
|
-
...args: Args<Events, EventName>
|
|
526
|
-
): void;
|
|
527
|
-
[EventEmitter.captureRejectionSymbol]?<EventName extends string | symbol>(
|
|
528
|
-
error: Error,
|
|
529
|
-
event: EventName,
|
|
530
|
-
...args: Args<Events, EventName>
|
|
531
|
-
): void;
|
|
384
|
+
interface EventEmitter<T extends EventMap<T> = DefaultEventMap> {
|
|
385
|
+
[EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: Key<K, T>, ...args: Args<K, T>): void;
|
|
532
386
|
/**
|
|
533
387
|
* Alias for `emitter.on(eventName, listener)`.
|
|
534
388
|
* @since v0.1.26
|
|
535
389
|
*/
|
|
536
|
-
addListener<
|
|
537
|
-
eventName: EventName,
|
|
538
|
-
listener: Listener<Events, EventName>,
|
|
539
|
-
): this;
|
|
540
|
-
addListener<EventName extends string | symbol>(
|
|
541
|
-
eventName: EventName,
|
|
542
|
-
listener: Listener<Events, EventName>,
|
|
543
|
-
): this;
|
|
390
|
+
addListener<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
|
|
544
391
|
/**
|
|
545
|
-
* Adds the `listener` function to the end of the listeners array for the
|
|
546
|
-
* named `eventName`. No checks are made to see if the `listener` has
|
|
547
|
-
* been added. Multiple calls passing the same combination of `eventName` and
|
|
548
|
-
*
|
|
392
|
+
* Adds the `listener` function to the end of the listeners array for the
|
|
393
|
+
* event named `eventName`. No checks are made to see if the `listener` has
|
|
394
|
+
* already been added. Multiple calls passing the same combination of `eventName` and `listener` will result in the `listener` being added, and called, multiple
|
|
395
|
+
* times.
|
|
549
396
|
*
|
|
550
397
|
* ```js
|
|
551
398
|
* server.on('connection', (stream) => {
|
|
@@ -555,11 +402,10 @@ declare module "events" {
|
|
|
555
402
|
*
|
|
556
403
|
* Returns a reference to the `EventEmitter`, so that calls can be chained.
|
|
557
404
|
*
|
|
558
|
-
* By default, event listeners are invoked in the order they are added. The
|
|
405
|
+
* 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
|
|
559
406
|
* event listener to the beginning of the listeners array.
|
|
560
407
|
*
|
|
561
408
|
* ```js
|
|
562
|
-
* const EventEmitter = require('events');
|
|
563
409
|
* const myEE = new EventEmitter();
|
|
564
410
|
* myEE.on('foo', () => console.log('a'));
|
|
565
411
|
* myEE.prependListener('foo', () => console.log('b'));
|
|
@@ -572,16 +418,9 @@ declare module "events" {
|
|
|
572
418
|
* @param eventName The name of the event.
|
|
573
419
|
* @param listener The callback function
|
|
574
420
|
*/
|
|
575
|
-
on<
|
|
576
|
-
eventName: EventName,
|
|
577
|
-
listener: Listener<Events, EventName>,
|
|
578
|
-
): this;
|
|
579
|
-
on<EventName extends string | symbol>(
|
|
580
|
-
eventName: EventName,
|
|
581
|
-
listener: Listener<Events, EventName>,
|
|
582
|
-
): this;
|
|
421
|
+
on<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
|
|
583
422
|
/**
|
|
584
|
-
* Adds a **one-time
|
|
423
|
+
* Adds a **one-time**`listener` function for the event named `eventName`. The
|
|
585
424
|
* next time `eventName` is triggered, this listener is removed and then invoked.
|
|
586
425
|
*
|
|
587
426
|
* ```js
|
|
@@ -592,11 +431,10 @@ declare module "events" {
|
|
|
592
431
|
*
|
|
593
432
|
* Returns a reference to the `EventEmitter`, so that calls can be chained.
|
|
594
433
|
*
|
|
595
|
-
* By default, event listeners are invoked in the order they are added. The
|
|
434
|
+
* 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
|
|
596
435
|
* event listener to the beginning of the listeners array.
|
|
597
436
|
*
|
|
598
437
|
* ```js
|
|
599
|
-
* const EventEmitter = require('events');
|
|
600
438
|
* const myEE = new EventEmitter();
|
|
601
439
|
* myEE.once('foo', () => console.log('a'));
|
|
602
440
|
* myEE.prependOnceListener('foo', () => console.log('b'));
|
|
@@ -609,16 +447,9 @@ declare module "events" {
|
|
|
609
447
|
* @param eventName The name of the event.
|
|
610
448
|
* @param listener The callback function
|
|
611
449
|
*/
|
|
612
|
-
once<
|
|
613
|
-
eventName: EventName,
|
|
614
|
-
listener: Listener<Events, EventName>,
|
|
615
|
-
): this;
|
|
616
|
-
once<EventName extends string | symbol>(
|
|
617
|
-
eventName: EventName,
|
|
618
|
-
listener: Listener<Events, EventName>,
|
|
619
|
-
): this;
|
|
450
|
+
once<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
|
|
620
451
|
/**
|
|
621
|
-
* Removes the specified `listener` from the listener array for the event named
|
|
452
|
+
* Removes the specified `listener` from the listener array for the event named`eventName`.
|
|
622
453
|
*
|
|
623
454
|
* ```js
|
|
624
455
|
* const callback = (stream) => {
|
|
@@ -635,12 +466,10 @@ declare module "events" {
|
|
|
635
466
|
* called multiple times to remove each instance.
|
|
636
467
|
*
|
|
637
468
|
* Once an event is emitted, all listeners attached to it at the
|
|
638
|
-
* time of emitting are called in order. This implies that any
|
|
639
|
-
*
|
|
469
|
+
* 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
|
|
470
|
+
* not remove them from`emit()` in progress. Subsequent events behave as expected.
|
|
640
471
|
*
|
|
641
472
|
* ```js
|
|
642
|
-
* const EventEmitter = require('events');
|
|
643
|
-
* class MyEmitter extends EventEmitter {}
|
|
644
473
|
* const myEmitter = new MyEmitter();
|
|
645
474
|
*
|
|
646
475
|
* const callbackA = () => {
|
|
@@ -678,10 +507,9 @@ declare module "events" {
|
|
|
678
507
|
*
|
|
679
508
|
* When a single function has been added as a handler multiple times for a single
|
|
680
509
|
* event (as in the example below), `removeListener()` will remove the most
|
|
681
|
-
* recently added instance. In the example the `once('ping')`
|
|
510
|
+
* recently added instance. In the example the `once('ping')`listener is removed:
|
|
682
511
|
*
|
|
683
512
|
* ```js
|
|
684
|
-
* const EventEmitter = require('events');
|
|
685
513
|
* const ee = new EventEmitter();
|
|
686
514
|
*
|
|
687
515
|
* function pong() {
|
|
@@ -699,26 +527,12 @@ declare module "events" {
|
|
|
699
527
|
* Returns a reference to the `EventEmitter`, so that calls can be chained.
|
|
700
528
|
* @since v0.1.26
|
|
701
529
|
*/
|
|
702
|
-
removeListener<
|
|
703
|
-
eventName: EventName,
|
|
704
|
-
listener: Listener<Events, EventName>,
|
|
705
|
-
): this;
|
|
706
|
-
removeListener<EventName extends string | symbol>(
|
|
707
|
-
eventName: EventName,
|
|
708
|
-
listener: Listener<Events, EventName>,
|
|
709
|
-
): this;
|
|
530
|
+
removeListener<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
|
|
710
531
|
/**
|
|
711
532
|
* Alias for `emitter.removeListener()`.
|
|
712
533
|
* @since v10.0.0
|
|
713
534
|
*/
|
|
714
|
-
off<
|
|
715
|
-
eventName: EventName,
|
|
716
|
-
listener: Listener<Events, EventName>,
|
|
717
|
-
): this;
|
|
718
|
-
off<EventName extends string | symbol>(
|
|
719
|
-
eventName: EventName,
|
|
720
|
-
listener: Listener<Events, EventName>,
|
|
721
|
-
): this;
|
|
535
|
+
off<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
|
|
722
536
|
/**
|
|
723
537
|
* Removes all listeners, or those of the specified `eventName`.
|
|
724
538
|
*
|
|
@@ -729,15 +543,12 @@ declare module "events" {
|
|
|
729
543
|
* Returns a reference to the `EventEmitter`, so that calls can be chained.
|
|
730
544
|
* @since v0.1.26
|
|
731
545
|
*/
|
|
732
|
-
|
|
733
|
-
removeAllListeners<EventName extends EventNames<Events>>(eventName: EventName): this;
|
|
734
|
-
removeAllListeners<EventName extends string | symbol>(eventName?: EventName): this;
|
|
735
|
-
/* eslint-enable @definitelytyped/no-unnecessary-generics */
|
|
546
|
+
removeAllListeners(event?: Key<unknown, T>): this;
|
|
736
547
|
/**
|
|
737
548
|
* By default `EventEmitter`s will print a warning if more than `10` listeners are
|
|
738
549
|
* added for a particular event. This is a useful default that helps finding
|
|
739
550
|
* memory leaks. The `emitter.setMaxListeners()` method allows the limit to be
|
|
740
|
-
* modified for this specific `EventEmitter` instance. The value can be set to
|
|
551
|
+
* modified for this specific `EventEmitter` instance. The value can be set to`Infinity` (or `0`) to indicate an unlimited number of listeners.
|
|
741
552
|
*
|
|
742
553
|
* Returns a reference to the `EventEmitter`, so that calls can be chained.
|
|
743
554
|
* @since v0.3.5
|
|
@@ -761,18 +572,12 @@ declare module "events" {
|
|
|
761
572
|
* ```
|
|
762
573
|
* @since v0.1.26
|
|
763
574
|
*/
|
|
764
|
-
listeners<
|
|
765
|
-
eventName: EventName,
|
|
766
|
-
): Array<Listener<Events, EventName>>;
|
|
767
|
-
listeners<EventName extends string | symbol>(
|
|
768
|
-
eventName: EventName,
|
|
769
|
-
): Array<Listener<Events, EventName>>;
|
|
575
|
+
listeners<K>(eventName: Key<K, T>): Array<Listener2<K, T>>;
|
|
770
576
|
/**
|
|
771
577
|
* Returns a copy of the array of listeners for the event named `eventName`,
|
|
772
578
|
* including any wrappers (such as those created by `.once()`).
|
|
773
579
|
*
|
|
774
580
|
* ```js
|
|
775
|
-
* const EventEmitter = require('events');
|
|
776
581
|
* const emitter = new EventEmitter();
|
|
777
582
|
* emitter.once('log', () => console.log('log once'));
|
|
778
583
|
*
|
|
@@ -797,14 +602,9 @@ declare module "events" {
|
|
|
797
602
|
* ```
|
|
798
603
|
* @since v9.4.0
|
|
799
604
|
*/
|
|
800
|
-
rawListeners<
|
|
801
|
-
eventName: EventName,
|
|
802
|
-
): Array<Listener<Events, EventName>>;
|
|
803
|
-
rawListeners<EventName extends string | symbol>(
|
|
804
|
-
eventName: EventName,
|
|
805
|
-
): Array<Listener<Events, EventName>>;
|
|
605
|
+
rawListeners<K>(eventName: Key<K, T>): Array<Listener2<K, T>>;
|
|
806
606
|
/**
|
|
807
|
-
* Synchronously calls each of the listeners registered for the event named
|
|
607
|
+
* Synchronously calls each of the listeners registered for the event named`eventName`, in the order they were registered, passing the supplied arguments
|
|
808
608
|
* to each.
|
|
809
609
|
*
|
|
810
610
|
* Returns `true` if the event had listeners, `false` otherwise.
|
|
@@ -843,35 +643,18 @@ declare module "events" {
|
|
|
843
643
|
* ```
|
|
844
644
|
* @since v0.1.26
|
|
845
645
|
*/
|
|
846
|
-
emit<
|
|
847
|
-
eventName: EventName,
|
|
848
|
-
...args: Args<Events, EventName>
|
|
849
|
-
): boolean;
|
|
850
|
-
emit<EventName extends string | symbol>(
|
|
851
|
-
eventName: EventName,
|
|
852
|
-
...args: Args<Events, EventName>
|
|
853
|
-
): boolean;
|
|
646
|
+
emit<K>(eventName: Key<K, T>, ...args: Args<K, T>): boolean;
|
|
854
647
|
/**
|
|
855
|
-
* Returns the number of listeners listening
|
|
856
|
-
* If `listener` is provided, it will return how many times the listener is found
|
|
857
|
-
* in the list of the listeners of the event.
|
|
648
|
+
* Returns the number of listeners listening to the event named `eventName`.
|
|
858
649
|
* @since v3.2.0
|
|
859
650
|
* @param eventName The name of the event being listened for
|
|
860
|
-
* @param listener The event handler function
|
|
861
651
|
*/
|
|
862
|
-
listenerCount<
|
|
863
|
-
eventName: EventName,
|
|
864
|
-
listener?: Listener<Events, EventName>,
|
|
865
|
-
): number;
|
|
866
|
-
listenerCount<EventName extends string | symbol>(
|
|
867
|
-
eventName: EventName,
|
|
868
|
-
listener?: Listener<Events, EventName>,
|
|
869
|
-
): number;
|
|
652
|
+
listenerCount<K>(eventName: Key<K, T>, listener?: Listener2<K, T>): number;
|
|
870
653
|
/**
|
|
871
654
|
* Adds the `listener` function to the _beginning_ of the listeners array for the
|
|
872
655
|
* event named `eventName`. No checks are made to see if the `listener` has
|
|
873
|
-
* already been added. Multiple calls passing the same combination of `eventName`
|
|
874
|
-
*
|
|
656
|
+
* already been added. Multiple calls passing the same combination of `eventName` and `listener` will result in the `listener` being added, and called, multiple
|
|
657
|
+
* times.
|
|
875
658
|
*
|
|
876
659
|
* ```js
|
|
877
660
|
* server.prependListener('connection', (stream) => {
|
|
@@ -884,16 +667,9 @@ declare module "events" {
|
|
|
884
667
|
* @param eventName The name of the event.
|
|
885
668
|
* @param listener The callback function
|
|
886
669
|
*/
|
|
887
|
-
prependListener<
|
|
888
|
-
eventName: EventName,
|
|
889
|
-
listener: Listener<Events, EventName>,
|
|
890
|
-
): this;
|
|
891
|
-
prependListener<EventName extends string | symbol>(
|
|
892
|
-
eventName: EventName,
|
|
893
|
-
listener: Listener<Events, EventName>,
|
|
894
|
-
): this;
|
|
670
|
+
prependListener<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
|
|
895
671
|
/**
|
|
896
|
-
* Adds a **one-time**`listener` function for the event named `eventName` to
|
|
672
|
+
* 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
|
|
897
673
|
* listener is removed, and then invoked.
|
|
898
674
|
*
|
|
899
675
|
* ```js
|
|
@@ -907,14 +683,7 @@ declare module "events" {
|
|
|
907
683
|
* @param eventName The name of the event.
|
|
908
684
|
* @param listener The callback function
|
|
909
685
|
*/
|
|
910
|
-
prependOnceListener<
|
|
911
|
-
eventName: EventName,
|
|
912
|
-
listener: Listener<Events, EventName>,
|
|
913
|
-
): this;
|
|
914
|
-
prependOnceListener<EventName extends string | symbol>(
|
|
915
|
-
eventName: EventName,
|
|
916
|
-
listener: Listener<Events, EventName>,
|
|
917
|
-
): this;
|
|
686
|
+
prependOnceListener<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
|
|
918
687
|
/**
|
|
919
688
|
* Returns an array listing the events for which the emitter has registered
|
|
920
689
|
* listeners. The values in the array are strings or `Symbol`s.
|
|
@@ -933,7 +702,7 @@ declare module "events" {
|
|
|
933
702
|
* ```
|
|
934
703
|
* @since v6.0.0
|
|
935
704
|
*/
|
|
936
|
-
eventNames(): Array<(string | symbol)
|
|
705
|
+
eventNames(): Array<(string | symbol) & Key2<unknown, T>>;
|
|
937
706
|
}
|
|
938
707
|
}
|
|
939
708
|
}
|
node v16.18/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@types/node",
|
|
3
|
-
"version": "16.18.
|
|
3
|
+
"version": "16.18.118",
|
|
4
4
|
"description": "TypeScript definitions for node",
|
|
5
5
|
"homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node",
|
|
6
6
|
"license": "MIT",
|
|
@@ -218,6 +218,6 @@
|
|
|
218
218
|
"scripts": {},
|
|
219
219
|
"dependencies": {},
|
|
220
220
|
"peerDependencies": {},
|
|
221
|
-
"typesPublisherContentHash": "
|
|
221
|
+
"typesPublisherContentHash": "89bf8903de3ba398de8f681a07b47774e7bd8cc7ee302ce637d310f2781cf850",
|
|
222
222
|
"typeScriptVersion": "4.8"
|
|
223
223
|
}
|