@types/node 25.0.2 → 25.0.3
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/README.md +1 -1
- node/events.d.ts +390 -382
- node/package.json +2 -2
node/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.
|
|
9
9
|
|
|
10
10
|
### Additional Details
|
|
11
|
-
* Last updated:
|
|
11
|
+
* Last updated: Tue, 16 Dec 2025 21:35:18 GMT
|
|
12
12
|
* Dependencies: [undici-types](https://npmjs.com/package/undici-types)
|
|
13
13
|
|
|
14
14
|
# Credits
|
node/events.d.ts
CHANGED
|
@@ -88,376 +88,390 @@ declare module "node:events" {
|
|
|
88
88
|
*/
|
|
89
89
|
class EventEmitter<T extends EventMap<T> = any> {
|
|
90
90
|
constructor(options?: EventEmitterOptions);
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
91
|
+
}
|
|
92
|
+
interface EventEmitter<T extends EventMap<T> = any> extends NodeJS.EventEmitter<T> {}
|
|
93
|
+
global {
|
|
94
|
+
namespace NodeJS {
|
|
95
|
+
interface EventEmitter<T extends EventMap<T> = any> {
|
|
96
|
+
/**
|
|
97
|
+
* The `Symbol.for('nodejs.rejection')` method is called in case a
|
|
98
|
+
* promise rejection happens when emitting an event and
|
|
99
|
+
* `captureRejections` is enabled on the emitter.
|
|
100
|
+
* It is possible to use `events.captureRejectionSymbol` in
|
|
101
|
+
* place of `Symbol.for('nodejs.rejection')`.
|
|
102
|
+
*
|
|
103
|
+
* ```js
|
|
104
|
+
* import { EventEmitter, captureRejectionSymbol } from 'node:events';
|
|
105
|
+
*
|
|
106
|
+
* class MyClass extends EventEmitter {
|
|
107
|
+
* constructor() {
|
|
108
|
+
* super({ captureRejections: true });
|
|
109
|
+
* }
|
|
110
|
+
*
|
|
111
|
+
* [captureRejectionSymbol](err, event, ...args) {
|
|
112
|
+
* console.log('rejection happened for', event, 'with', err, ...args);
|
|
113
|
+
* this.destroy(err);
|
|
114
|
+
* }
|
|
115
|
+
*
|
|
116
|
+
* destroy(err) {
|
|
117
|
+
* // Tear the resource down here.
|
|
118
|
+
* }
|
|
119
|
+
* }
|
|
120
|
+
* ```
|
|
121
|
+
* @since v13.4.0, v12.16.0
|
|
122
|
+
*/
|
|
123
|
+
[EventEmitter.captureRejectionSymbol]?(error: Error, event: string | symbol, ...args: any[]): void;
|
|
124
|
+
/**
|
|
125
|
+
* Alias for `emitter.on(eventName, listener)`.
|
|
126
|
+
* @since v0.1.26
|
|
127
|
+
*/
|
|
128
|
+
addListener<E extends string | symbol>(eventName: EventNames<T, E>, listener: Listener<T, E>): this;
|
|
129
|
+
/**
|
|
130
|
+
* Synchronously calls each of the listeners registered for the event named
|
|
131
|
+
* `eventName`, in the order they were registered, passing the supplied arguments
|
|
132
|
+
* to each.
|
|
133
|
+
*
|
|
134
|
+
* Returns `true` if the event had listeners, `false` otherwise.
|
|
135
|
+
*
|
|
136
|
+
* ```js
|
|
137
|
+
* import { EventEmitter } from 'node:events';
|
|
138
|
+
* const myEmitter = new EventEmitter();
|
|
139
|
+
*
|
|
140
|
+
* // First listener
|
|
141
|
+
* myEmitter.on('event', function firstListener() {
|
|
142
|
+
* console.log('Helloooo! first listener');
|
|
143
|
+
* });
|
|
144
|
+
* // Second listener
|
|
145
|
+
* myEmitter.on('event', function secondListener(arg1, arg2) {
|
|
146
|
+
* console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
|
|
147
|
+
* });
|
|
148
|
+
* // Third listener
|
|
149
|
+
* myEmitter.on('event', function thirdListener(...args) {
|
|
150
|
+
* const parameters = args.join(', ');
|
|
151
|
+
* console.log(`event with parameters ${parameters} in third listener`);
|
|
152
|
+
* });
|
|
153
|
+
*
|
|
154
|
+
* console.log(myEmitter.listeners('event'));
|
|
155
|
+
*
|
|
156
|
+
* myEmitter.emit('event', 1, 2, 3, 4, 5);
|
|
157
|
+
*
|
|
158
|
+
* // Prints:
|
|
159
|
+
* // [
|
|
160
|
+
* // [Function: firstListener],
|
|
161
|
+
* // [Function: secondListener],
|
|
162
|
+
* // [Function: thirdListener]
|
|
163
|
+
* // ]
|
|
164
|
+
* // Helloooo! first listener
|
|
165
|
+
* // event with parameters 1, 2 in second listener
|
|
166
|
+
* // event with parameters 1, 2, 3, 4, 5 in third listener
|
|
167
|
+
* ```
|
|
168
|
+
* @since v0.1.26
|
|
169
|
+
*/
|
|
170
|
+
emit<E extends string | symbol>(eventName: EventNames<T, E>, ...args: Args<T, E>): boolean;
|
|
171
|
+
/**
|
|
172
|
+
* Returns an array listing the events for which the emitter has registered
|
|
173
|
+
* listeners.
|
|
174
|
+
*
|
|
175
|
+
* ```js
|
|
176
|
+
* import { EventEmitter } from 'node:events';
|
|
177
|
+
*
|
|
178
|
+
* const myEE = new EventEmitter();
|
|
179
|
+
* myEE.on('foo', () => {});
|
|
180
|
+
* myEE.on('bar', () => {});
|
|
181
|
+
*
|
|
182
|
+
* const sym = Symbol('symbol');
|
|
183
|
+
* myEE.on(sym, () => {});
|
|
184
|
+
*
|
|
185
|
+
* console.log(myEE.eventNames());
|
|
186
|
+
* // Prints: [ 'foo', 'bar', Symbol(symbol) ]
|
|
187
|
+
* ```
|
|
188
|
+
* @since v6.0.0
|
|
189
|
+
*/
|
|
190
|
+
eventNames(): (string | symbol)[];
|
|
191
|
+
/**
|
|
192
|
+
* Returns the current max listener value for the `EventEmitter` which is either
|
|
193
|
+
* set by `emitter.setMaxListeners(n)` or defaults to
|
|
194
|
+
* `events.defaultMaxListeners`.
|
|
195
|
+
* @since v1.0.0
|
|
196
|
+
*/
|
|
197
|
+
getMaxListeners(): number;
|
|
198
|
+
/**
|
|
199
|
+
* Returns the number of listeners listening for the event named `eventName`.
|
|
200
|
+
* If `listener` is provided, it will return how many times the listener is found
|
|
201
|
+
* in the list of the listeners of the event.
|
|
202
|
+
* @since v3.2.0
|
|
203
|
+
* @param eventName The name of the event being listened for
|
|
204
|
+
* @param listener The event handler function
|
|
205
|
+
*/
|
|
206
|
+
listenerCount<E extends string | symbol>(
|
|
207
|
+
eventName: EventNames<T, E>,
|
|
208
|
+
listener?: Listener<T, E>,
|
|
209
|
+
): number;
|
|
210
|
+
/**
|
|
211
|
+
* Returns a copy of the array of listeners for the event named `eventName`.
|
|
212
|
+
*
|
|
213
|
+
* ```js
|
|
214
|
+
* server.on('connection', (stream) => {
|
|
215
|
+
* console.log('someone connected!');
|
|
216
|
+
* });
|
|
217
|
+
* console.log(util.inspect(server.listeners('connection')));
|
|
218
|
+
* // Prints: [ [Function] ]
|
|
219
|
+
* ```
|
|
220
|
+
* @since v0.1.26
|
|
221
|
+
*/
|
|
222
|
+
listeners<E extends string | symbol>(eventName: EventNames<T, E>): Listener<T, E>[];
|
|
223
|
+
/**
|
|
224
|
+
* Alias for `emitter.removeListener()`.
|
|
225
|
+
* @since v10.0.0
|
|
226
|
+
*/
|
|
227
|
+
off<E extends string | symbol>(eventName: EventNames<T, E>, listener: Listener<T, E>): this;
|
|
228
|
+
/**
|
|
229
|
+
* Adds the `listener` function to the end of the listeners array for the
|
|
230
|
+
* event named `eventName`. No checks are made to see if the `listener` has
|
|
231
|
+
* already been added. Multiple calls passing the same combination of `eventName`
|
|
232
|
+
* and `listener` will result in the `listener` being added, and called, multiple
|
|
233
|
+
* times.
|
|
234
|
+
*
|
|
235
|
+
* ```js
|
|
236
|
+
* server.on('connection', (stream) => {
|
|
237
|
+
* console.log('someone connected!');
|
|
238
|
+
* });
|
|
239
|
+
* ```
|
|
240
|
+
*
|
|
241
|
+
* Returns a reference to the `EventEmitter`, so that calls can be chained.
|
|
242
|
+
*
|
|
243
|
+
* By default, event listeners are invoked in the order they are added. The
|
|
244
|
+
* `emitter.prependListener()` method can be used as an alternative to add the
|
|
245
|
+
* event listener to the beginning of the listeners array.
|
|
246
|
+
*
|
|
247
|
+
* ```js
|
|
248
|
+
* import { EventEmitter } from 'node:events';
|
|
249
|
+
* const myEE = new EventEmitter();
|
|
250
|
+
* myEE.on('foo', () => console.log('a'));
|
|
251
|
+
* myEE.prependListener('foo', () => console.log('b'));
|
|
252
|
+
* myEE.emit('foo');
|
|
253
|
+
* // Prints:
|
|
254
|
+
* // b
|
|
255
|
+
* // a
|
|
256
|
+
* ```
|
|
257
|
+
* @since v0.1.101
|
|
258
|
+
* @param eventName The name of the event.
|
|
259
|
+
* @param listener The callback function
|
|
260
|
+
*/
|
|
261
|
+
on<E extends string | symbol>(eventName: EventNames<T, E>, listener: Listener<T, E>): this;
|
|
262
|
+
/**
|
|
263
|
+
* Adds a **one-time** `listener` function for the event named `eventName`. The
|
|
264
|
+
* next time `eventName` is triggered, this listener is removed and then invoked.
|
|
265
|
+
*
|
|
266
|
+
* ```js
|
|
267
|
+
* server.once('connection', (stream) => {
|
|
268
|
+
* console.log('Ah, we have our first user!');
|
|
269
|
+
* });
|
|
270
|
+
* ```
|
|
271
|
+
*
|
|
272
|
+
* Returns a reference to the `EventEmitter`, so that calls can be chained.
|
|
273
|
+
*
|
|
274
|
+
* By default, event listeners are invoked in the order they are added. The
|
|
275
|
+
* `emitter.prependOnceListener()` method can be used as an alternative to add the
|
|
276
|
+
* event listener to the beginning of the listeners array.
|
|
277
|
+
*
|
|
278
|
+
* ```js
|
|
279
|
+
* import { EventEmitter } from 'node:events';
|
|
280
|
+
* const myEE = new EventEmitter();
|
|
281
|
+
* myEE.once('foo', () => console.log('a'));
|
|
282
|
+
* myEE.prependOnceListener('foo', () => console.log('b'));
|
|
283
|
+
* myEE.emit('foo');
|
|
284
|
+
* // Prints:
|
|
285
|
+
* // b
|
|
286
|
+
* // a
|
|
287
|
+
* ```
|
|
288
|
+
* @since v0.3.0
|
|
289
|
+
* @param eventName The name of the event.
|
|
290
|
+
* @param listener The callback function
|
|
291
|
+
*/
|
|
292
|
+
once<E extends string | symbol>(eventName: EventNames<T, E>, listener: Listener<T, E>): this;
|
|
293
|
+
/**
|
|
294
|
+
* Adds the `listener` function to the _beginning_ of the listeners array for the
|
|
295
|
+
* event named `eventName`. No checks are made to see if the `listener` has
|
|
296
|
+
* already been added. Multiple calls passing the same combination of `eventName`
|
|
297
|
+
* and `listener` will result in the `listener` being added, and called, multiple
|
|
298
|
+
* times.
|
|
299
|
+
*
|
|
300
|
+
* ```js
|
|
301
|
+
* server.prependListener('connection', (stream) => {
|
|
302
|
+
* console.log('someone connected!');
|
|
303
|
+
* });
|
|
304
|
+
* ```
|
|
305
|
+
*
|
|
306
|
+
* Returns a reference to the `EventEmitter`, so that calls can be chained.
|
|
307
|
+
* @since v6.0.0
|
|
308
|
+
* @param eventName The name of the event.
|
|
309
|
+
* @param listener The callback function
|
|
310
|
+
*/
|
|
311
|
+
prependListener<E extends string | symbol>(eventName: EventNames<T, E>, listener: Listener<T, E>): this;
|
|
312
|
+
/**
|
|
313
|
+
* Adds a **one-time** `listener` function for the event named `eventName` to the
|
|
314
|
+
* _beginning_ of the listeners array. The next time `eventName` is triggered, this
|
|
315
|
+
* listener is removed, and then invoked.
|
|
316
|
+
*
|
|
317
|
+
* ```js
|
|
318
|
+
* server.prependOnceListener('connection', (stream) => {
|
|
319
|
+
* console.log('Ah, we have our first user!');
|
|
320
|
+
* });
|
|
321
|
+
* ```
|
|
322
|
+
*
|
|
323
|
+
* Returns a reference to the `EventEmitter`, so that calls can be chained.
|
|
324
|
+
* @since v6.0.0
|
|
325
|
+
* @param eventName The name of the event.
|
|
326
|
+
* @param listener The callback function
|
|
327
|
+
*/
|
|
328
|
+
prependOnceListener<E extends string | symbol>(
|
|
329
|
+
eventName: EventNames<T, E>,
|
|
330
|
+
listener: Listener<T, E>,
|
|
331
|
+
): this;
|
|
332
|
+
/**
|
|
333
|
+
* Returns a copy of the array of listeners for the event named `eventName`,
|
|
334
|
+
* including any wrappers (such as those created by `.once()`).
|
|
335
|
+
*
|
|
336
|
+
* ```js
|
|
337
|
+
* import { EventEmitter } from 'node:events';
|
|
338
|
+
* const emitter = new EventEmitter();
|
|
339
|
+
* emitter.once('log', () => console.log('log once'));
|
|
340
|
+
*
|
|
341
|
+
* // Returns a new Array with a function `onceWrapper` which has a property
|
|
342
|
+
* // `listener` which contains the original listener bound above
|
|
343
|
+
* const listeners = emitter.rawListeners('log');
|
|
344
|
+
* const logFnWrapper = listeners[0];
|
|
345
|
+
*
|
|
346
|
+
* // Logs "log once" to the console and does not unbind the `once` event
|
|
347
|
+
* logFnWrapper.listener();
|
|
348
|
+
*
|
|
349
|
+
* // Logs "log once" to the console and removes the listener
|
|
350
|
+
* logFnWrapper();
|
|
351
|
+
*
|
|
352
|
+
* emitter.on('log', () => console.log('log persistently'));
|
|
353
|
+
* // Will return a new Array with a single function bound by `.on()` above
|
|
354
|
+
* const newListeners = emitter.rawListeners('log');
|
|
355
|
+
*
|
|
356
|
+
* // Logs "log persistently" twice
|
|
357
|
+
* newListeners[0]();
|
|
358
|
+
* emitter.emit('log');
|
|
359
|
+
* ```
|
|
360
|
+
* @since v9.4.0
|
|
361
|
+
*/
|
|
362
|
+
rawListeners<E extends string | symbol>(eventName: EventNames<T, E>): Listener<T, E>[];
|
|
363
|
+
/**
|
|
364
|
+
* Removes all listeners, or those of the specified `eventName`.
|
|
365
|
+
*
|
|
366
|
+
* It is bad practice to remove listeners added elsewhere in the code,
|
|
367
|
+
* particularly when the `EventEmitter` instance was created by some other
|
|
368
|
+
* component or module (e.g. sockets or file streams).
|
|
369
|
+
*
|
|
370
|
+
* Returns a reference to the `EventEmitter`, so that calls can be chained.
|
|
371
|
+
* @since v0.1.26
|
|
372
|
+
*/
|
|
373
|
+
// eslint-disable-next-line @definitelytyped/no-unnecessary-generics
|
|
374
|
+
removeAllListeners<E extends string | symbol>(eventName?: EventNames<T, E>): this;
|
|
375
|
+
/**
|
|
376
|
+
* Removes the specified `listener` from the listener array for the event named
|
|
377
|
+
* `eventName`.
|
|
378
|
+
*
|
|
379
|
+
* ```js
|
|
380
|
+
* const callback = (stream) => {
|
|
381
|
+
* console.log('someone connected!');
|
|
382
|
+
* };
|
|
383
|
+
* server.on('connection', callback);
|
|
384
|
+
* // ...
|
|
385
|
+
* server.removeListener('connection', callback);
|
|
386
|
+
* ```
|
|
387
|
+
*
|
|
388
|
+
* `removeListener()` will remove, at most, one instance of a listener from the
|
|
389
|
+
* listener array. If any single listener has been added multiple times to the
|
|
390
|
+
* listener array for the specified `eventName`, then `removeListener()` must be
|
|
391
|
+
* called multiple times to remove each instance.
|
|
392
|
+
*
|
|
393
|
+
* Once an event is emitted, all listeners attached to it at the
|
|
394
|
+
* time of emitting are called in order. This implies that any
|
|
395
|
+
* `removeListener()` or `removeAllListeners()` calls _after_ emitting and
|
|
396
|
+
* _before_ the last listener finishes execution will not remove them from
|
|
397
|
+
* `emit()` in progress. Subsequent events behave as expected.
|
|
398
|
+
*
|
|
399
|
+
* ```js
|
|
400
|
+
* import { EventEmitter } from 'node:events';
|
|
401
|
+
* class MyEmitter extends EventEmitter {}
|
|
402
|
+
* const myEmitter = new MyEmitter();
|
|
403
|
+
*
|
|
404
|
+
* const callbackA = () => {
|
|
405
|
+
* console.log('A');
|
|
406
|
+
* myEmitter.removeListener('event', callbackB);
|
|
407
|
+
* };
|
|
408
|
+
*
|
|
409
|
+
* const callbackB = () => {
|
|
410
|
+
* console.log('B');
|
|
411
|
+
* };
|
|
412
|
+
*
|
|
413
|
+
* myEmitter.on('event', callbackA);
|
|
414
|
+
*
|
|
415
|
+
* myEmitter.on('event', callbackB);
|
|
416
|
+
*
|
|
417
|
+
* // callbackA removes listener callbackB but it will still be called.
|
|
418
|
+
* // Internal listener array at time of emit [callbackA, callbackB]
|
|
419
|
+
* myEmitter.emit('event');
|
|
420
|
+
* // Prints:
|
|
421
|
+
* // A
|
|
422
|
+
* // B
|
|
423
|
+
*
|
|
424
|
+
* // callbackB is now removed.
|
|
425
|
+
* // Internal listener array [callbackA]
|
|
426
|
+
* myEmitter.emit('event');
|
|
427
|
+
* // Prints:
|
|
428
|
+
* // A
|
|
429
|
+
* ```
|
|
430
|
+
*
|
|
431
|
+
* Because listeners are managed using an internal array, calling this will
|
|
432
|
+
* change the position indexes of any listener registered _after_ the listener
|
|
433
|
+
* being removed. This will not impact the order in which listeners are called,
|
|
434
|
+
* but it means that any copies of the listener array as returned by
|
|
435
|
+
* the `emitter.listeners()` method will need to be recreated.
|
|
436
|
+
*
|
|
437
|
+
* When a single function has been added as a handler multiple times for a single
|
|
438
|
+
* event (as in the example below), `removeListener()` will remove the most
|
|
439
|
+
* recently added instance. In the example the `once('ping')`
|
|
440
|
+
* listener is removed:
|
|
441
|
+
*
|
|
442
|
+
* ```js
|
|
443
|
+
* import { EventEmitter } from 'node:events';
|
|
444
|
+
* const ee = new EventEmitter();
|
|
445
|
+
*
|
|
446
|
+
* function pong() {
|
|
447
|
+
* console.log('pong');
|
|
448
|
+
* }
|
|
449
|
+
*
|
|
450
|
+
* ee.on('ping', pong);
|
|
451
|
+
* ee.once('ping', pong);
|
|
452
|
+
* ee.removeListener('ping', pong);
|
|
453
|
+
*
|
|
454
|
+
* ee.emit('ping');
|
|
455
|
+
* ee.emit('ping');
|
|
456
|
+
* ```
|
|
457
|
+
*
|
|
458
|
+
* Returns a reference to the `EventEmitter`, so that calls can be chained.
|
|
459
|
+
* @since v0.1.26
|
|
460
|
+
*/
|
|
461
|
+
removeListener<E extends string | symbol>(eventName: EventNames<T, E>, listener: Listener<T, E>): this;
|
|
462
|
+
/**
|
|
463
|
+
* By default `EventEmitter`s will print a warning if more than `10` listeners are
|
|
464
|
+
* added for a particular event. This is a useful default that helps finding
|
|
465
|
+
* memory leaks. The `emitter.setMaxListeners()` method allows the limit to be
|
|
466
|
+
* modified for this specific `EventEmitter` instance. The value can be set to
|
|
467
|
+
* `Infinity` (or `0`) to indicate an unlimited number of listeners.
|
|
468
|
+
*
|
|
469
|
+
* Returns a reference to the `EventEmitter`, so that calls can be chained.
|
|
470
|
+
* @since v0.3.5
|
|
471
|
+
*/
|
|
472
|
+
setMaxListeners(n: number): this;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
461
475
|
}
|
|
462
476
|
namespace EventEmitter {
|
|
463
477
|
export { EventEmitter, EventEmitterEventMap, EventEmitterOptions };
|
|
@@ -592,7 +606,7 @@ declare module "node:events" {
|
|
|
592
606
|
* ```
|
|
593
607
|
* @since v15.2.0, v14.17.0
|
|
594
608
|
*/
|
|
595
|
-
function getEventListeners(emitter:
|
|
609
|
+
function getEventListeners(emitter: EventEmitter, name: string | symbol): ((...args: any[]) => void)[];
|
|
596
610
|
function getEventListeners(emitter: EventTarget, name: string): ((...args: any[]) => void)[];
|
|
597
611
|
/**
|
|
598
612
|
* Returns the currently set max amount of listeners.
|
|
@@ -622,7 +636,7 @@ declare module "node:events" {
|
|
|
622
636
|
* ```
|
|
623
637
|
* @since v19.9.0
|
|
624
638
|
*/
|
|
625
|
-
function getMaxListeners(emitter:
|
|
639
|
+
function getMaxListeners(emitter: EventEmitter | EventTarget): number;
|
|
626
640
|
/**
|
|
627
641
|
* A class method that returns the number of listeners for the given `eventName`
|
|
628
642
|
* registered on the given `emitter`.
|
|
@@ -641,7 +655,7 @@ declare module "node:events" {
|
|
|
641
655
|
* @param emitter The emitter to query
|
|
642
656
|
* @param eventName The event name
|
|
643
657
|
*/
|
|
644
|
-
function listenerCount(emitter:
|
|
658
|
+
function listenerCount(emitter: EventEmitter, eventName: string | symbol): number;
|
|
645
659
|
interface OnOptions extends Abortable {
|
|
646
660
|
/**
|
|
647
661
|
* Names of events that will end the iteration.
|
|
@@ -721,7 +735,7 @@ declare module "node:events" {
|
|
|
721
735
|
* @returns `AsyncIterator` that iterates `eventName` events emitted by the `emitter`
|
|
722
736
|
*/
|
|
723
737
|
function on(
|
|
724
|
-
emitter:
|
|
738
|
+
emitter: EventEmitter,
|
|
725
739
|
eventName: string | symbol,
|
|
726
740
|
options?: OnOptions,
|
|
727
741
|
): NodeJS.AsyncIterator<any[]>;
|
|
@@ -812,7 +826,7 @@ declare module "node:events" {
|
|
|
812
826
|
* @since v11.13.0, v10.16.0
|
|
813
827
|
*/
|
|
814
828
|
function once(
|
|
815
|
-
emitter:
|
|
829
|
+
emitter: EventEmitter,
|
|
816
830
|
eventName: string | symbol,
|
|
817
831
|
options?: OnceOptions,
|
|
818
832
|
): Promise<any[]>;
|
|
@@ -833,7 +847,7 @@ declare module "node:events" {
|
|
|
833
847
|
* max for all newly created `EventTarget` and `EventEmitter` objects.
|
|
834
848
|
* objects.
|
|
835
849
|
*/
|
|
836
|
-
function setMaxListeners(n: number, ...eventTargets: ReadonlyArray<
|
|
850
|
+
function setMaxListeners(n: number, ...eventTargets: ReadonlyArray<EventEmitter | EventTarget>): void;
|
|
837
851
|
/**
|
|
838
852
|
* This is the interface from which event-emitting Node.js APIs inherit in the types package.
|
|
839
853
|
* **It is not intended for consumer use.**
|
|
@@ -1032,12 +1046,6 @@ declare module "node:events" {
|
|
|
1032
1046
|
[K in keyof T & string as `on${K}`]: ((ev: T[K]) => void) | null;
|
|
1033
1047
|
};
|
|
1034
1048
|
}
|
|
1035
|
-
global {
|
|
1036
|
-
import _ = EventEmitter;
|
|
1037
|
-
namespace NodeJS {
|
|
1038
|
-
interface EventEmitter<T extends EventMap<T> = any> extends _<T> {}
|
|
1039
|
-
}
|
|
1040
|
-
}
|
|
1041
1049
|
export = EventEmitter;
|
|
1042
1050
|
}
|
|
1043
1051
|
declare module "events" {
|
node/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@types/node",
|
|
3
|
-
"version": "25.0.
|
|
3
|
+
"version": "25.0.3",
|
|
4
4
|
"description": "TypeScript definitions for node",
|
|
5
5
|
"homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node",
|
|
6
6
|
"license": "MIT",
|
|
@@ -150,6 +150,6 @@
|
|
|
150
150
|
"undici-types": "~7.16.0"
|
|
151
151
|
},
|
|
152
152
|
"peerDependencies": {},
|
|
153
|
-
"typesPublisherContentHash": "
|
|
153
|
+
"typesPublisherContentHash": "f232fc4d25235ca95f233b42be2cfd08c384791f716e60e2c105ff6db6b0bdc4",
|
|
154
154
|
"typeScriptVersion": "5.2"
|
|
155
155
|
}
|