@types/node 20.4.9 → 20.5.0

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 CHANGED
@@ -8,7 +8,7 @@ This package contains type definitions for Node.js (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: Tue, 08 Aug 2023 20:32:42 GMT
11
+ * Last updated: Sun, 13 Aug 2023 19:32:51 GMT
12
12
  * Dependencies: none
13
13
  * Global values: `AbortController`, `AbortSignal`, `__dirname`, `__filename`, `console`, `exports`, `gc`, `global`, `module`, `process`, `require`, `structuredClone`
14
14
 
node/child_process.d.ts CHANGED
@@ -302,6 +302,11 @@ declare module 'child_process' {
302
302
  * @since v0.1.90
303
303
  */
304
304
  kill(signal?: NodeJS.Signals | number): boolean;
305
+ /**
306
+ * Calls {@link ChildProcess.kill} with `'SIGTERM'`.
307
+ * @since v20.5.0
308
+ */
309
+ [Symbol.dispose](): void;
305
310
  /**
306
311
  * When an IPC channel has been established between the parent and child (
307
312
  * i.e. when using {@link fork}), the `subprocess.send()` method can
node/dgram.d.ts CHANGED
@@ -538,6 +538,11 @@ declare module 'dgram' {
538
538
  prependOnceListener(event: 'error', listener: (err: Error) => void): this;
539
539
  prependOnceListener(event: 'listening', listener: () => void): this;
540
540
  prependOnceListener(event: 'message', listener: (msg: Buffer, rinfo: RemoteInfo) => void): this;
541
+ /**
542
+ * Calls `socket.close()` and returns a promise that fulfills when the socket has closed.
543
+ * @since v20.5.0
544
+ */
545
+ [Symbol.asyncDispose](): Promise<void>;
541
546
  }
542
547
  }
543
548
  declare module 'node:dgram' {
node/events.d.ts CHANGED
@@ -338,6 +338,41 @@ declare module 'events' {
338
338
  * objects.
339
339
  */
340
340
  static setMaxListeners(n?: number, ...eventTargets: Array<_DOMEventTarget | NodeJS.EventEmitter>): void;
341
+ /**
342
+ * Listens once to the `abort` event on the provided `signal`.
343
+ *
344
+ * Listening to the `abort` event on abort signals is unsafe and may
345
+ * lead to resource leaks since another third party with the signal can
346
+ * call `e.stopImmediatePropagation()`. Unfortunately Node.js cannot change
347
+ * this since it would violate the web standard. Additionally, the original
348
+ * API makes it easy to forget to remove listeners.
349
+ *
350
+ * This API allows safely using `AbortSignal`s in Node.js APIs by solving these
351
+ * two issues by listening to the event such that `stopImmediatePropagation` does
352
+ * not prevent the listener from running.
353
+ *
354
+ * Returns a disposable so that it may be unsubscribed from more easily.
355
+ *
356
+ * ```js
357
+ * import { addAbortListener } from 'node:events';
358
+ *
359
+ * function example(signal) {
360
+ * let disposable;
361
+ * try {
362
+ * signal.addEventListener('abort', (e) => e.stopImmediatePropagation());
363
+ * disposable = addAbortListener(signal, (e) => {
364
+ * // Do something when signal is aborted.
365
+ * });
366
+ * } finally {
367
+ * disposable?.[Symbol.dispose]();
368
+ * }
369
+ * }
370
+ * ```
371
+ * @since v20.5.0
372
+ * @experimental
373
+ * @return that removes the `abort` listener.
374
+ */
375
+ static addAbortListener(signal: AbortSignal, resource: (event: Event) => void): Disposable;
341
376
  /**
342
377
  * This symbol shall be used to install a listener for only monitoring `'error'`events. Listeners installed using this symbol are called before the regular`'error'` listeners are called.
343
378
  *
node/fs/promises.d.ts CHANGED
@@ -456,6 +456,11 @@ declare module 'fs/promises' {
456
456
  * @return Fulfills with `undefined` upon success.
457
457
  */
458
458
  close(): Promise<void>;
459
+ /**
460
+ * An alias for {@link FileHandle.close()}.
461
+ * @since v20.4.0
462
+ */
463
+ [Symbol.asyncDispose](): Promise<void>;
459
464
  }
460
465
  const constants: typeof fsConstants;
461
466
  /**
node/globals.d.ts CHANGED
@@ -84,6 +84,28 @@ declare var AbortSignal: typeof globalThis extends {onmessage: any; AbortSignal:
84
84
  };
85
85
  //#endregion borrowed
86
86
 
87
+ //#region Disposable
88
+ interface SymbolConstructor {
89
+ /**
90
+ * A method that is used to release resources held by an object. Called by the semantics of the `using` statement.
91
+ */
92
+ readonly dispose: unique symbol;
93
+
94
+ /**
95
+ * A method that is used to asynchronously release resources held by an object. Called by the semantics of the `await using` statement.
96
+ */
97
+ readonly asyncDispose: unique symbol;
98
+ }
99
+
100
+ interface Disposable {
101
+ [Symbol.dispose](): void;
102
+ }
103
+
104
+ interface AsyncDisposable {
105
+ [Symbol.asyncDispose](): PromiseLike<void>;
106
+ }
107
+ //#endregion Disposable
108
+
87
109
  //#region ArrayLike.at()
88
110
  interface RelativeIndexable<T> {
89
111
  /**
node/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Type definitions for non-npm package Node.js 20.4
1
+ // Type definitions for non-npm package Node.js 20.5
2
2
  // Project: https://nodejs.org/
3
3
  // Definitions by: Microsoft TypeScript <https://github.com/Microsoft>
4
4
  // DefinitelyTyped <https://github.com/DefinitelyTyped>
node/net.d.ts CHANGED
@@ -639,6 +639,11 @@ declare module 'net' {
639
639
  prependOnceListener(event: 'error', listener: (err: Error) => void): this;
640
640
  prependOnceListener(event: 'listening', listener: () => void): this;
641
641
  prependOnceListener(event: 'drop', listener: (data?: DropArgument) => void): this;
642
+ /**
643
+ * Calls {@link Server.close()} and returns a promise that fulfills when the server has closed.
644
+ * @since v20.5.0
645
+ */
646
+ [Symbol.asyncDispose](): Promise<void>;
642
647
  }
643
648
  type IPVersion = 'ipv4' | 'ipv6';
644
649
  /**
node/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@types/node",
3
- "version": "20.4.9",
3
+ "version": "20.5.0",
4
4
  "description": "TypeScript definitions for Node.js",
5
5
  "homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node",
6
6
  "license": "MIT",
@@ -227,6 +227,6 @@
227
227
  },
228
228
  "scripts": {},
229
229
  "dependencies": {},
230
- "typesPublisherContentHash": "b2f4c2c06161f1c6a01968b024abf85b1541142467b4d7a7fe451165a706da3f",
230
+ "typesPublisherContentHash": "83e291a6a60ec56a2b56b6b885ae9a0ea199888a482d63f4a22270483f82f2a9",
231
231
  "typeScriptVersion": "4.3"
232
232
  }
node/stream.d.ts CHANGED
@@ -477,6 +477,11 @@ declare module 'stream' {
477
477
  removeListener(event: 'resume', listener: () => void): this;
478
478
  removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
479
479
  [Symbol.asyncIterator](): AsyncIterableIterator<any>;
480
+ /**
481
+ * Calls `readable.destroy()` with an `AbortError` and returns a promise that fulfills when the stream is finished.
482
+ * @since v20.4.0
483
+ */
484
+ [Symbol.asyncDispose](): Promise<void>;
480
485
  }
481
486
  import WritableOptions = internal.WritableOptions;
482
487
  class WritableBase extends Stream implements NodeJS.WritableStream {
node/test.d.ts CHANGED
@@ -259,6 +259,16 @@ declare module 'node:test' {
259
259
  * If the test uses callbacks, the callback function is passed as an argument
260
260
  */
261
261
  type SuiteFn = (s: SuiteContext) => void | Promise<void>;
262
+ interface TestShard {
263
+ /**
264
+ * A positive integer between 1 and `<total>` that specifies the index of the shard to run.
265
+ */
266
+ index: number;
267
+ /**
268
+ * A positive integer that specifies the total number of shards to split the test files to.
269
+ */
270
+ total: number;
271
+ }
262
272
  interface RunOptions {
263
273
  /**
264
274
  * If a number is provided, then that many files would run in parallel.
@@ -301,9 +311,15 @@ declare module 'node:test' {
301
311
  */
302
312
  setup?: (root: Test) => void | Promise<void>;
303
313
  /**
304
- * Whether to run in watch mode or not. Default: false.
314
+ * Whether to run in watch mode or not.
315
+ * @default false
305
316
  */
306
- watch?: boolean;
317
+ watch?: boolean | undefined;
318
+ /**
319
+ * Running tests in a specific shard.
320
+ * @default undefined
321
+ */
322
+ shard?: TestShard | undefined;
307
323
  }
308
324
  class Test extends AsyncResource {
309
325
  concurrency: number;
@@ -1210,6 +1226,10 @@ declare module 'node:test' {
1210
1226
  * @since v20.4.0
1211
1227
  */
1212
1228
  runAll(): void;
1229
+ /**
1230
+ * Calls {@link MockTimers.reset()}.
1231
+ */
1232
+ [Symbol.dispose](): void;
1213
1233
  }
1214
1234
  export { test as default, run, test, describe, it, before, after, beforeEach, afterEach, mock, skip, only, todo };
1215
1235
  }
@@ -1241,6 +1261,11 @@ interface TestFail {
1241
1261
  * The error thrown by the test.
1242
1262
  */
1243
1263
  error: Error;
1264
+ /**
1265
+ * The type of the test, used to denote whether this is a suite.
1266
+ * @since 20.0.0, 19.9.0, 18.17.0
1267
+ */
1268
+ type?: 'suite';
1244
1269
  };
1245
1270
  /**
1246
1271
  * The test name.
@@ -1276,6 +1301,11 @@ interface TestPass {
1276
1301
  * The duration of the test in milliseconds.
1277
1302
  */
1278
1303
  duration_ms: number;
1304
+ /**
1305
+ * The type of the test, used to denote whether this is a suite.
1306
+ * @since 20.0.0, 19.9.0, 18.17.0
1307
+ */
1308
+ type?: 'suite';
1279
1309
  };
1280
1310
  /**
1281
1311
  * The test name.
node/timers.d.ts CHANGED
@@ -68,6 +68,11 @@ declare module 'timers' {
68
68
  */
69
69
  hasRef(): boolean;
70
70
  _onImmediate: Function; // to distinguish it from the Timeout class
71
+ /**
72
+ * Cancels the immediate. This is similar to calling `clearImmediate()`.
73
+ * @since v20.5.0
74
+ */
75
+ [Symbol.dispose](): void;
71
76
  }
72
77
  /**
73
78
  * This object is created internally and is returned from `setTimeout()` and `setInterval()`. It can be passed to either `clearTimeout()` or `clearInterval()` in order to cancel the
@@ -114,6 +119,11 @@ declare module 'timers' {
114
119
  */
115
120
  refresh(): this;
116
121
  [Symbol.toPrimitive](): number;
122
+ /**
123
+ * Cancels the timeout.
124
+ * @since v20.5.0
125
+ */
126
+ [Symbol.dispose](): void;
117
127
  }
118
128
  }
119
129
  /**
@@ -163,10 +173,10 @@ declare module 'timers' {
163
173
  * @param args Optional arguments to pass when the `callback` is called.
164
174
  * @return for use with {@link clearInterval}
165
175
  */
166
- function setInterval<TArgs extends any[]>(callback: (...args: TArgs) => void, ms?: number, ...args: TArgs): NodeJS.Timer;
176
+ function setInterval<TArgs extends any[]>(callback: (...args: TArgs) => void, ms?: number, ...args: TArgs): NodeJS.Timeout;
167
177
  // util.promisify no rest args compability
168
178
  // tslint:disable-next-line void-return
169
- function setInterval(callback: (args: void) => void, ms?: number): NodeJS.Timer;
179
+ function setInterval(callback: (args: void) => void, ms?: number): NodeJS.Timeout;
170
180
  namespace setInterval {
171
181
  const __promisify__: typeof setIntervalPromise;
172
182
  }
@@ -302,6 +302,11 @@ declare module 'child_process' {
302
302
  * @since v0.1.90
303
303
  */
304
304
  kill(signal?: NodeJS.Signals | number): boolean;
305
+ /**
306
+ * Calls {@link ChildProcess.kill} with `'SIGTERM'`.
307
+ * @since v20.5.0
308
+ */
309
+ [Symbol.dispose](): void;
305
310
  /**
306
311
  * When an IPC channel has been established between the parent and child (
307
312
  * i.e. when using {@link fork}), the `subprocess.send()` method can
node/ts4.8/dgram.d.ts CHANGED
@@ -538,6 +538,11 @@ declare module 'dgram' {
538
538
  prependOnceListener(event: 'error', listener: (err: Error) => void): this;
539
539
  prependOnceListener(event: 'listening', listener: () => void): this;
540
540
  prependOnceListener(event: 'message', listener: (msg: Buffer, rinfo: RemoteInfo) => void): this;
541
+ /**
542
+ * Calls `socket.close()` and returns a promise that fulfills when the socket has closed.
543
+ * @since v20.5.0
544
+ */
545
+ [Symbol.asyncDispose](): Promise<void>;
541
546
  }
542
547
  }
543
548
  declare module 'node:dgram' {
node/ts4.8/events.d.ts CHANGED
@@ -338,6 +338,41 @@ declare module 'events' {
338
338
  * objects.
339
339
  */
340
340
  static setMaxListeners(n?: number, ...eventTargets: Array<_DOMEventTarget | NodeJS.EventEmitter>): void;
341
+ /**
342
+ * Listens once to the `abort` event on the provided `signal`.
343
+ *
344
+ * Listening to the `abort` event on abort signals is unsafe and may
345
+ * lead to resource leaks since another third party with the signal can
346
+ * call `e.stopImmediatePropagation()`. Unfortunately Node.js cannot change
347
+ * this since it would violate the web standard. Additionally, the original
348
+ * API makes it easy to forget to remove listeners.
349
+ *
350
+ * This API allows safely using `AbortSignal`s in Node.js APIs by solving these
351
+ * two issues by listening to the event such that `stopImmediatePropagation` does
352
+ * not prevent the listener from running.
353
+ *
354
+ * Returns a disposable so that it may be unsubscribed from more easily.
355
+ *
356
+ * ```js
357
+ * import { addAbortListener } from 'node:events';
358
+ *
359
+ * function example(signal) {
360
+ * let disposable;
361
+ * try {
362
+ * signal.addEventListener('abort', (e) => e.stopImmediatePropagation());
363
+ * disposable = addAbortListener(signal, (e) => {
364
+ * // Do something when signal is aborted.
365
+ * });
366
+ * } finally {
367
+ * disposable?.[Symbol.dispose]();
368
+ * }
369
+ * }
370
+ * ```
371
+ * @since v20.5.0
372
+ * @experimental
373
+ * @return that removes the `abort` listener.
374
+ */
375
+ static addAbortListener(signal: AbortSignal, resource: (event: Event) => void): Disposable;
341
376
  /**
342
377
  * This symbol shall be used to install a listener for only monitoring `'error'`events. Listeners installed using this symbol are called before the regular`'error'` listeners are called.
343
378
  *
@@ -456,6 +456,11 @@ declare module 'fs/promises' {
456
456
  * @return Fulfills with `undefined` upon success.
457
457
  */
458
458
  close(): Promise<void>;
459
+ /**
460
+ * An alias for {@link FileHandle.close()}.
461
+ * @since v20.4.0
462
+ */
463
+ [Symbol.asyncDispose](): Promise<void>;
459
464
  }
460
465
  const constants: typeof fsConstants;
461
466
  /**
node/ts4.8/globals.d.ts CHANGED
@@ -84,6 +84,28 @@ declare var AbortSignal: typeof globalThis extends {onmessage: any; AbortSignal:
84
84
  };
85
85
  //#endregion borrowed
86
86
 
87
+ //#region Disposable
88
+ interface SymbolConstructor {
89
+ /**
90
+ * A method that is used to release resources held by an object. Called by the semantics of the `using` statement.
91
+ */
92
+ readonly dispose: unique symbol;
93
+
94
+ /**
95
+ * A method that is used to asynchronously release resources held by an object. Called by the semantics of the `await using` statement.
96
+ */
97
+ readonly asyncDispose: unique symbol;
98
+ }
99
+
100
+ interface Disposable {
101
+ [Symbol.dispose](): void;
102
+ }
103
+
104
+ interface AsyncDisposable {
105
+ [Symbol.asyncDispose](): PromiseLike<void>;
106
+ }
107
+ //#endregion Disposable
108
+
87
109
  //#region ArrayLike.at()
88
110
  interface RelativeIndexable<T> {
89
111
  /**
node/ts4.8/net.d.ts CHANGED
@@ -639,6 +639,11 @@ declare module 'net' {
639
639
  prependOnceListener(event: 'error', listener: (err: Error) => void): this;
640
640
  prependOnceListener(event: 'listening', listener: () => void): this;
641
641
  prependOnceListener(event: 'drop', listener: (data?: DropArgument) => void): this;
642
+ /**
643
+ * Calls {@link Server.close()} and returns a promise that fulfills when the server has closed.
644
+ * @since v20.5.0
645
+ */
646
+ [Symbol.asyncDispose](): Promise<void>;
642
647
  }
643
648
  type IPVersion = 'ipv4' | 'ipv6';
644
649
  /**