@types/node 18.19.62 → 18.19.64

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 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: Thu, 31 Oct 2024 05:35:24 GMT
11
+ * Last updated: Sun, 03 Nov 2024 04:02:17 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,12 +34,13 @@
34
34
  * ```
35
35
  * @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/events.js)
36
36
  */
37
-
38
37
  declare module "events" {
39
38
  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
+
43
44
  // import { EventListener, EventListenerObject } from '__dom-events';
44
45
  // /** The NodeEventTarget is a Node.js-specific extension to EventTarget that emulates a subset of the EventEmitter API. */
45
46
  // interface NodeEventTarget extends EventTarget {
@@ -70,6 +71,7 @@ declare module "events" {
70
71
  // */
71
72
  // removeListener(type: string, listener: EventListener | EventListenerObject): this;
72
73
  // }
74
+
73
75
  interface EventEmitterOptions {
74
76
  /**
75
77
  * Enables automatic capturing of promise rejection.
@@ -91,33 +93,25 @@ declare module "events" {
91
93
  ): any;
92
94
  }
93
95
  interface StaticEventEmitterOptions {
94
- /**
95
- * Can be used to cancel awaiting events.
96
- */
97
96
  signal?: AbortSignal | undefined;
98
97
  }
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
-
98
+ interface EventEmitter<T extends EventMap<T> = DefaultEventMap> extends NodeJS.EventEmitter<T> {}
99
+ type EventMap<T> = Record<keyof T, any[]> | DefaultEventMap;
100
+ type DefaultEventMap = [never];
101
+ type AnyRest = [...args: any[]];
102
+ type Args<K, T> = T extends DefaultEventMap ? AnyRest : (
103
+ K extends keyof T ? T[K] : never
104
+ );
105
+ type Key<K, T> = T extends DefaultEventMap ? string | symbol : K | keyof T;
106
+ type Key2<K, T> = T extends DefaultEventMap ? string | symbol : K & keyof T;
107
+ type Listener<K, T, F> = T extends DefaultEventMap ? F : (
108
+ K extends keyof T ? (
109
+ T[K] extends unknown[] ? (...args: T[K]) => void : never
110
+ )
111
+ : never
112
+ );
113
+ type Listener1<K, T> = Listener<K, T, (...args: any[]) => void>;
114
+ type Listener2<K, T> = Listener<K, T, Function>;
121
115
  /**
122
116
  * The `EventEmitter` class is defined and exposed by the `events` module:
123
117
  *
@@ -131,20 +125,10 @@ declare module "events" {
131
125
  * It supports the following option:
132
126
  * @since v0.1.26
133
127
  */
134
- class EventEmitter<Events extends EventMap<Events> = {}> {
128
+ class EventEmitter<T extends EventMap<T> = DefaultEventMap> {
135
129
  constructor(options?: EventEmitterOptions);
136
130
 
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;
131
+ [EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: Key<K, T>, ...args: Args<K, T>): void;
148
132
 
149
133
  /**
150
134
  * Creates a `Promise` that is fulfilled when the `EventEmitter` emits the given
@@ -228,11 +212,6 @@ declare module "events" {
228
212
  * ```
229
213
  * @since v11.13.0, v10.16.0
230
214
  */
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>>;
236
215
  static once(
237
216
  emitter: _NodeEventTarget,
238
217
  eventName: string | symbol,
@@ -294,20 +273,16 @@ declare module "events" {
294
273
  * process.nextTick(() => ac.abort());
295
274
  * ```
296
275
  * @since v13.6.0, v12.16.0
297
- * @return An `AsyncIterator` that iterates `eventName` events emitted by the `emitter`
276
+ * @param eventName The name of the event being listened for
277
+ * @return that iterates `eventName` events emitted by the `emitter`
298
278
  */
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>>;
304
279
  static on(
305
280
  emitter: NodeJS.EventEmitter,
306
- eventName: string | symbol,
281
+ eventName: string,
307
282
  options?: StaticEventEmitterOptions,
308
- ): NodeJS.AsyncIterator<any[]>;
283
+ ): NodeJS.AsyncIterator<any>;
309
284
  /**
310
- * A class method that returns the number of listeners for the given `eventName` registered on the given `emitter`.
285
+ * A class method that returns the number of listeners for the given `eventName`registered on the given `emitter`.
311
286
  *
312
287
  * ```js
313
288
  * import { EventEmitter, listenerCount } from 'node:events';
@@ -322,27 +297,6 @@ declare module "events" {
322
297
  * @param emitter The emitter to query
323
298
  * @param eventName The event name
324
299
  */
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
- */
346
300
  static listenerCount(emitter: NodeJS.EventEmitter, eventName: string | symbol): number;
347
301
  /**
348
302
  * Returns a copy of the array of listeners for the event named `eventName`.
@@ -360,21 +314,17 @@ declare module "events" {
360
314
  * const ee = new EventEmitter();
361
315
  * const listener = () => console.log('Events are fun');
362
316
  * ee.on('foo', listener);
363
- * console.log(getEventListeners(ee, 'foo')); // [ [Function: listener] ]
317
+ * getEventListeners(ee, 'foo'); // [listener]
364
318
  * }
365
319
  * {
366
320
  * const et = new EventTarget();
367
321
  * const listener = () => console.log('Events are fun');
368
322
  * et.addEventListener('foo', listener);
369
- * console.log(getEventListeners(et, 'foo')); // [ [Function: listener] ]
323
+ * getEventListeners(et, 'foo'); // [listener]
370
324
  * }
371
325
  * ```
372
326
  * @since v15.2.0, v14.17.0
373
327
  */
374
- static getEventListeners<Events extends EventMap<Events>, EventName extends EventNames<Events>>(
375
- emitter: EventEmitter<Events>,
376
- name: EventName,
377
- ): Array<Listener<Events, EventName>>;
378
328
  static getEventListeners(emitter: _DOMEventTarget | NodeJS.EventEmitter, name: string | symbol): Function[];
379
329
  /**
380
330
  * Returns the currently set max amount of listeners.
@@ -387,7 +337,7 @@ declare module "events" {
387
337
  * the max set, the EventTarget will print a warning.
388
338
  *
389
339
  * ```js
390
- * const { getMaxListeners, setMaxListeners, EventEmitter } = require('events');
340
+ * import { getMaxListeners, setMaxListeners, EventEmitter } from 'node:events';
391
341
  *
392
342
  * {
393
343
  * const ee = new EventEmitter();
@@ -439,7 +389,7 @@ declare module "events" {
439
389
  * Returns a disposable so that it may be unsubscribed from more easily.
440
390
  *
441
391
  * ```js
442
- * const { addAbortListener } = require('events');
392
+ * import { addAbortListener } from 'node:events';
443
393
  *
444
394
  * function example(signal) {
445
395
  * let disposable;
@@ -468,58 +418,12 @@ declare module "events" {
468
418
  * regular `'error'` listener is installed.
469
419
  */
470
420
  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
- */
477
421
  static readonly captureRejectionSymbol: unique symbol;
478
422
  /**
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
423
+ * Sets or gets the default captureRejection value for all emitters.
483
424
  */
425
+ // TODO: These should be described using static getter/setter pairs:
484
426
  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
- */
523
427
  static defaultMaxListeners: number;
524
428
  }
525
429
  import internal = require("node:events");
@@ -547,41 +451,13 @@ declare module "events" {
547
451
  }
548
452
 
549
453
  /**
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
- * });
454
+ * Integrates `EventEmitter` with `AsyncResource` for `EventEmitter`s that require
455
+ * manual async tracking. Specifically, all events emitted by instances of
456
+ * `EventEmitterAsyncResource` will run within its async context.
567
457
  *
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.
458
+ * The EventEmitterAsyncResource class has the same methods and takes the
459
+ * same options as EventEmitter and AsyncResource themselves.
460
+ * @throws if `options.name` is not provided when instantiated directly.
585
461
  * @since v17.4.0, v16.14.0
586
462
  */
587
463
  export class EventEmitterAsyncResource extends EventEmitter {
@@ -590,62 +466,34 @@ declare module "events" {
590
466
  */
591
467
  constructor(options?: EventEmitterAsyncResourceOptions);
592
468
  /**
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.
469
+ * Call all destroy hooks. This should only ever be called once. An
470
+ * error will be thrown if it is called more than once. This must be
471
+ * manually called. If the resource is left to be collected by the GC then
472
+ * the destroy hooks will never be called.
597
473
  */
598
474
  emitDestroy(): void;
599
- /**
600
- * The unique `asyncId` assigned to the resource.
601
- */
475
+ /** The unique asyncId assigned to the resource. */
602
476
  readonly asyncId: number;
603
- /**
604
- * The same triggerAsyncId that is passed to the AsyncResource constructor.
605
- */
477
+ /** The same triggerAsyncId that is passed to the AsyncResource constructor. */
606
478
  readonly triggerAsyncId: number;
607
- /**
608
- * The returned `AsyncResource` object has an additional `eventEmitter` property
609
- * that provides a reference to this `EventEmitterAsyncResource`.
610
- */
479
+ /** The underlying AsyncResource */
611
480
  readonly asyncResource: EventEmitterReferencingAsyncResource;
612
481
  }
613
-
614
- export interface EventEmitterBuiltInEventMap {
615
- newListener: [eventName: string | symbol, listener: Function];
616
- removeListener: [eventName: string | symbol, listener: Function];
617
- }
618
482
  }
619
483
  global {
620
484
  namespace NodeJS {
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;
485
+ interface EventEmitter<T extends EventMap<T> = DefaultEventMap> {
486
+ [EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: Key<K, T>, ...args: Args<K, T>): void;
632
487
  /**
633
488
  * Alias for `emitter.on(eventName, listener)`.
634
489
  * @since v0.1.26
635
490
  */
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;
491
+ addListener<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
644
492
  /**
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.
493
+ * Adds the `listener` function to the end of the listeners array for the
494
+ * event named `eventName`. No checks are made to see if the `listener` has
495
+ * already been added. Multiple calls passing the same combination of `eventName` and `listener` will result in the `listener` being added, and called, multiple
496
+ * times.
649
497
  *
650
498
  * ```js
651
499
  * server.on('connection', (stream) => {
@@ -655,11 +503,10 @@ declare module "events" {
655
503
  *
656
504
  * Returns a reference to the `EventEmitter`, so that calls can be chained.
657
505
  *
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
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
659
507
  * event listener to the beginning of the listeners array.
660
508
  *
661
509
  * ```js
662
- * const EventEmitter = require('events');
663
510
  * const myEE = new EventEmitter();
664
511
  * myEE.on('foo', () => console.log('a'));
665
512
  * myEE.prependListener('foo', () => console.log('b'));
@@ -672,16 +519,9 @@ declare module "events" {
672
519
  * @param eventName The name of the event.
673
520
  * @param listener The callback function
674
521
  */
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;
522
+ on<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
683
523
  /**
684
- * Adds a **one-time** `listener` function for the event named `eventName`. The
524
+ * Adds a **one-time**`listener` function for the event named `eventName`. The
685
525
  * next time `eventName` is triggered, this listener is removed and then invoked.
686
526
  *
687
527
  * ```js
@@ -692,11 +532,10 @@ declare module "events" {
692
532
  *
693
533
  * Returns a reference to the `EventEmitter`, so that calls can be chained.
694
534
  *
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
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
696
536
  * event listener to the beginning of the listeners array.
697
537
  *
698
538
  * ```js
699
- * const EventEmitter = require('events');
700
539
  * const myEE = new EventEmitter();
701
540
  * myEE.once('foo', () => console.log('a'));
702
541
  * myEE.prependOnceListener('foo', () => console.log('b'));
@@ -709,16 +548,9 @@ declare module "events" {
709
548
  * @param eventName The name of the event.
710
549
  * @param listener The callback function
711
550
  */
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;
551
+ once<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
720
552
  /**
721
- * Removes the specified `listener` from the listener array for the event named `eventName`.
553
+ * Removes the specified `listener` from the listener array for the event named`eventName`.
722
554
  *
723
555
  * ```js
724
556
  * const callback = (stream) => {
@@ -735,12 +567,10 @@ declare module "events" {
735
567
  * called multiple times to remove each instance.
736
568
  *
737
569
  * Once an event is emitted, all listeners attached to it at the
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
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
739
571
  * will not remove them from`emit()` in progress. Subsequent events behave as expected.
740
572
  *
741
573
  * ```js
742
- * const EventEmitter = require('events');
743
- * class MyEmitter extends EventEmitter {}
744
574
  * const myEmitter = new MyEmitter();
745
575
  *
746
576
  * const callbackA = () => {
@@ -778,10 +608,9 @@ declare module "events" {
778
608
  *
779
609
  * When a single function has been added as a handler multiple times for a single
780
610
  * event (as in the example below), `removeListener()` will remove the most
781
- * recently added instance. In the example the `once('ping')` listener is removed:
611
+ * recently added instance. In the example the `once('ping')`listener is removed:
782
612
  *
783
613
  * ```js
784
- * const EventEmitter = require('events');
785
614
  * const ee = new EventEmitter();
786
615
  *
787
616
  * function pong() {
@@ -799,26 +628,12 @@ declare module "events" {
799
628
  * Returns a reference to the `EventEmitter`, so that calls can be chained.
800
629
  * @since v0.1.26
801
630
  */
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;
631
+ removeListener<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
810
632
  /**
811
633
  * Alias for `emitter.removeListener()`.
812
634
  * @since v10.0.0
813
635
  */
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;
636
+ off<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
822
637
  /**
823
638
  * Removes all listeners, or those of the specified `eventName`.
824
639
  *
@@ -829,15 +644,12 @@ declare module "events" {
829
644
  * Returns a reference to the `EventEmitter`, so that calls can be chained.
830
645
  * @since v0.1.26
831
646
  */
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 */
647
+ removeAllListeners(event?: Key<unknown, T>): this;
836
648
  /**
837
649
  * By default `EventEmitter`s will print a warning if more than `10` listeners are
838
650
  * added for a particular event. This is a useful default that helps finding
839
651
  * memory leaks. The `emitter.setMaxListeners()` method allows the limit to be
840
- * modified for this specific `EventEmitter` instance. The value can be set to `Infinity` (or `0`) to indicate an unlimited number of listeners.
652
+ * modified for this specific `EventEmitter` instance. The value can be set to`Infinity` (or `0`) to indicate an unlimited number of listeners.
841
653
  *
842
654
  * Returns a reference to the `EventEmitter`, so that calls can be chained.
843
655
  * @since v0.3.5
@@ -861,18 +673,12 @@ declare module "events" {
861
673
  * ```
862
674
  * @since v0.1.26
863
675
  */
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>>;
676
+ listeners<K>(eventName: Key<K, T>): Array<Listener2<K, T>>;
870
677
  /**
871
678
  * Returns a copy of the array of listeners for the event named `eventName`,
872
679
  * including any wrappers (such as those created by `.once()`).
873
680
  *
874
681
  * ```js
875
- * const EventEmitter = require('events');
876
682
  * const emitter = new EventEmitter();
877
683
  * emitter.once('log', () => console.log('log once'));
878
684
  *
@@ -897,14 +703,9 @@ declare module "events" {
897
703
  * ```
898
704
  * @since v9.4.0
899
705
  */
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>>;
706
+ rawListeners<K>(eventName: Key<K, T>): Array<Listener2<K, T>>;
906
707
  /**
907
- * Synchronously calls each of the listeners registered for the event named `eventName`, in the order they were registered, passing the supplied arguments
708
+ * Synchronously calls each of the listeners registered for the event named`eventName`, in the order they were registered, passing the supplied arguments
908
709
  * to each.
909
710
  *
910
711
  * Returns `true` if the event had listeners, `false` otherwise.
@@ -943,35 +744,22 @@ declare module "events" {
943
744
  * ```
944
745
  * @since v0.1.26
945
746
  */
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;
747
+ emit<K>(eventName: Key<K, T>, ...args: Args<K, T>): boolean;
954
748
  /**
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.
749
+ * Returns the number of listeners listening to the event named `eventName`.
750
+ *
751
+ * If `listener` is provided, it will return how many times the listener
752
+ * is found in the list of the listeners of the event.
958
753
  * @since v3.2.0
959
754
  * @param eventName The name of the event being listened for
960
755
  * @param listener The event handler function
961
756
  */
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;
757
+ listenerCount<K>(eventName: Key<K, T>, listener?: Listener2<K, T>): number;
970
758
  /**
971
759
  * Adds the `listener` function to the _beginning_ of the listeners array for the
972
760
  * event named `eventName`. No checks are made to see if the `listener` has
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.
761
+ * already been added. Multiple calls passing the same combination of `eventName` and `listener` will result in the `listener` being added, and called, multiple
762
+ * times.
975
763
  *
976
764
  * ```js
977
765
  * server.prependListener('connection', (stream) => {
@@ -984,14 +772,7 @@ declare module "events" {
984
772
  * @param eventName The name of the event.
985
773
  * @param listener The callback function
986
774
  */
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;
775
+ prependListener<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
995
776
  /**
996
777
  * 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
997
778
  * listener is removed, and then invoked.
@@ -1007,14 +788,7 @@ declare module "events" {
1007
788
  * @param eventName The name of the event.
1008
789
  * @param listener The callback function
1009
790
  */
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;
791
+ prependOnceListener<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
1018
792
  /**
1019
793
  * Returns an array listing the events for which the emitter has registered
1020
794
  * listeners. The values in the array are strings or `Symbol`s.
@@ -1033,7 +807,7 @@ declare module "events" {
1033
807
  * ```
1034
808
  * @since v6.0.0
1035
809
  */
1036
- eventNames(): Array<(string | symbol)> & Array<EventNames<Events>>;
810
+ eventNames(): Array<(string | symbol) & Key2<unknown, T>>;
1037
811
  }
1038
812
  }
1039
813
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@types/node",
3
- "version": "18.19.62",
3
+ "version": "18.19.64",
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": "ea7c345bb61cffb74ee7ae872691ac155874e1506181f10dfd5d6f51a142ca34",
228
+ "typesPublisherContentHash": "e4626f38becfd7c9a0f9c63e938e8deaa99fdb13bf62133a5138caf0e4730c8e",
229
229
  "typeScriptVersion": "4.8"
230
230
  }
@@ -5,8 +5,13 @@
5
5
  * @since v17.0.0
6
6
  */
7
7
  declare module "readline/promises" {
8
- import { AsyncCompleter, Completer, Direction, Interface as _Interface, ReadLineOptions } from "node:readline";
9
8
  import { Abortable } from "node:events";
9
+ import {
10
+ CompleterResult,
11
+ Direction,
12
+ Interface as _Interface,
13
+ ReadLineOptions as _ReadLineOptions,
14
+ } from "node:readline";
10
15
 
11
16
  class Interface extends _Interface {
12
17
  /**
@@ -80,7 +85,13 @@ declare module "readline/promises" {
80
85
  */
81
86
  rollback(): this;
82
87
  }
83
-
88
+ type Completer = (line: string) => CompleterResult | Promise<CompleterResult>;
89
+ interface ReadLineOptions extends Omit<_ReadLineOptions, "completer"> {
90
+ /**
91
+ * An optional function used for Tab autocompletion.
92
+ */
93
+ completer?: Completer | undefined;
94
+ }
84
95
  /**
85
96
  * The `readlinePromises.createInterface()` method creates a new `readlinePromises.Interface` instance.
86
97
  *
@@ -133,7 +144,7 @@ declare module "readline/promises" {
133
144
  function createInterface(
134
145
  input: NodeJS.ReadableStream,
135
146
  output?: NodeJS.WritableStream,
136
- completer?: Completer | AsyncCompleter,
147
+ completer?: Completer,
137
148
  terminal?: boolean,
138
149
  ): Interface;
139
150
  function createInterface(options: ReadLineOptions): Interface;
@@ -100,7 +100,7 @@ declare module "readline" {
100
100
  * > Instances of the `readline.Interface` class are constructed using the
101
101
  * > `readline.createInterface()` method.
102
102
  *
103
- * @see https://nodejs.org/dist/latest-v10.x/docs/api/readline.html#readline_class_interface
103
+ * @see https://nodejs.org/docs/latest-v18.x/api/readline.html#readline_class_interface
104
104
  */
105
105
  protected constructor(
106
106
  input: NodeJS.ReadableStream,
@@ -114,7 +114,7 @@ declare module "readline" {
114
114
  * > Instances of the `readline.Interface` class are constructed using the
115
115
  * > `readline.createInterface()` method.
116
116
  *
117
- * @see https://nodejs.org/dist/latest-v10.x/docs/api/readline.html#readline_class_interface
117
+ * @see https://nodejs.org/docs/latest-v18.x/api/readline.html#readline_class_interface
118
118
  */
119
119
  protected constructor(options: ReadLineOptions);
120
120
  /**
@@ -331,29 +331,78 @@ declare module "readline" {
331
331
  ) => void;
332
332
  export type CompleterResult = [string[], string];
333
333
  export interface ReadLineOptions {
334
+ /**
335
+ * The [`Readable`](https://nodejs.org/docs/latest-v18.x/api/stream.html#readable-streams) stream to listen to
336
+ */
334
337
  input: NodeJS.ReadableStream;
338
+ /**
339
+ * The [`Writable`](https://nodejs.org/docs/latest-v18.x/api/stream.html#writable-streams) stream to write readline data to.
340
+ */
335
341
  output?: NodeJS.WritableStream | undefined;
342
+ /**
343
+ * An optional function used for Tab autocompletion.
344
+ */
336
345
  completer?: Completer | AsyncCompleter | undefined;
346
+ /**
347
+ * `true` if the `input` and `output` streams should be treated like a TTY,
348
+ * and have ANSI/VT100 escape codes written to it.
349
+ * Default: checking `isTTY` on the `output` stream upon instantiation.
350
+ */
337
351
  terminal?: boolean | undefined;
338
352
  /**
339
- * Initial list of history lines. This option makes sense
340
- * only if `terminal` is set to `true` by the user or by an internal `output`
341
- * check, otherwise the history caching mechanism is not initialized at all.
353
+ * Initial list of history lines.
354
+ * This option makes sense only if `terminal` is set to `true` by the user or by an internal `output` check,
355
+ * otherwise the history caching mechanism is not initialized at all.
342
356
  * @default []
343
357
  */
344
358
  history?: string[] | undefined;
359
+ /**
360
+ * Maximum number of history lines retained.
361
+ * To disable the history set this value to `0`.
362
+ * This option makes sense only if `terminal` is set to `true` by the user or by an internal `output` check,
363
+ * otherwise the history caching mechanism is not initialized at all.
364
+ * @default 30
365
+ */
345
366
  historySize?: number | undefined;
346
- prompt?: string | undefined;
347
- crlfDelay?: number | undefined;
348
367
  /**
349
- * If `true`, when a new input line added
350
- * to the history list duplicates an older one, this removes the older line
351
- * from the list.
368
+ * If `true`, when a new input line added to the history list duplicates an older one,
369
+ * this removes the older line from the list.
352
370
  * @default false
353
371
  */
354
372
  removeHistoryDuplicates?: boolean | undefined;
373
+ /**
374
+ * The prompt string to use.
375
+ * @default "> "
376
+ */
377
+ prompt?: string | undefined;
378
+ /**
379
+ * If the delay between `\r` and `\n` exceeds `crlfDelay` milliseconds,
380
+ * both `\r` and `\n` will be treated as separate end-of-line input.
381
+ * `crlfDelay` will be coerced to a number no less than `100`.
382
+ * It can be set to `Infinity`, in which case
383
+ * `\r` followed by `\n` will always be considered a single newline
384
+ * (which may be reasonable for [reading files](https://nodejs.org/docs/latest-v18.x/api/readline.html#example-read-file-stream-line-by-line) with `\r\n` line delimiter).
385
+ * @default 100
386
+ */
387
+ crlfDelay?: number | undefined;
388
+ /**
389
+ * The duration `readline` will wait for a character
390
+ * (when reading an ambiguous key sequence in milliseconds
391
+ * one that can both form a complete key sequence using the input read so far
392
+ * and can take additional input to complete a longer key sequence).
393
+ * @default 500
394
+ */
355
395
  escapeCodeTimeout?: number | undefined;
396
+ /**
397
+ * The number of spaces a tab is equal to (minimum 1).
398
+ * @default 8
399
+ */
356
400
  tabSize?: number | undefined;
401
+ /**
402
+ * Allows closing the interface using an AbortSignal.
403
+ * Aborting the signal will internally call `close` on the interface.
404
+ */
405
+ signal?: AbortSignal | undefined;
357
406
  }
358
407
  /**
359
408
  * The `readline.createInterface()` method creates a new `readline.Interface`instance.