@types/node 20.16.2 → 20.16.4

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 v20.16/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/v20.
9
9
 
10
10
  ### Additional Details
11
- * Last updated: Wed, 28 Aug 2024 00:27:14 GMT
11
+ * Last updated: Wed, 04 Sep 2024 00:28:08 GMT
12
12
  * Dependencies: [undici-types](https://npmjs.com/package/undici-types)
13
13
 
14
14
  # Credits
node v20.16/buffer.d.ts CHANGED
@@ -1,3 +1,8 @@
1
+ // If lib.dom.d.ts or lib.webworker.d.ts is loaded, then use the global types.
2
+ // Otherwise, use the types from node.
3
+ type _Blob = typeof globalThis extends { onmessage: any; Blob: any } ? {} : import("buffer").Blob;
4
+ type _File = typeof globalThis extends { onmessage: any; File: any } ? {} : import("buffer").File;
5
+
1
6
  /**
2
7
  * `Buffer` objects are used to represent a fixed-length sequence of bytes. Many
3
8
  * Node.js APIs support `Buffer`s.
@@ -233,10 +238,7 @@ declare module "buffer" {
233
238
  }
234
239
  export import atob = globalThis.atob;
235
240
  export import btoa = globalThis.btoa;
236
- import { Blob as NodeBlob } from "buffer";
237
- // This conditional type will be the existing global Blob in a browser, or
238
- // the copy below in a Node environment.
239
- type __Blob = typeof globalThis extends { onmessage: any; Blob: any } ? {} : NodeBlob;
241
+
240
242
  global {
241
243
  namespace NodeJS {
242
244
  export { BufferEncoding };
@@ -2276,17 +2278,22 @@ declare module "buffer" {
2276
2278
  * @param data An ASCII (Latin1) string.
2277
2279
  */
2278
2280
  function btoa(data: string): string;
2279
- interface Blob extends __Blob {}
2281
+ interface Blob extends _Blob {}
2280
2282
  /**
2281
2283
  * `Blob` class is a global reference for `require('node:buffer').Blob`
2282
2284
  * https://nodejs.org/api/buffer.html#class-blob
2283
2285
  * @since v18.0.0
2284
2286
  */
2285
- var Blob: typeof globalThis extends {
2286
- onmessage: any;
2287
- Blob: infer T;
2288
- } ? T
2289
- : typeof NodeBlob;
2287
+ var Blob: typeof globalThis extends { onmessage: any; Blob: infer T } ? T
2288
+ : typeof import("buffer").Blob;
2289
+ interface File extends _File {}
2290
+ /**
2291
+ * `File` class is a global reference for `require('node:buffer').File`
2292
+ * https://nodejs.org/api/buffer.html#class-file
2293
+ * @since v20.0.0
2294
+ */
2295
+ var File: typeof globalThis extends { onmessage: any; File: infer T } ? T
2296
+ : typeof import("buffer").File;
2290
2297
  }
2291
2298
  }
2292
2299
  declare module "node:buffer" {
@@ -7,13 +7,83 @@ type _Request = typeof globalThis extends { onmessage: any } ? {} : import("undi
7
7
  type _Response = typeof globalThis extends { onmessage: any } ? {} : import("undici-types").Response;
8
8
  type _FormData = typeof globalThis extends { onmessage: any } ? {} : import("undici-types").FormData;
9
9
  type _Headers = typeof globalThis extends { onmessage: any } ? {} : import("undici-types").Headers;
10
+ type _MessageEvent = typeof globalThis extends { onmessage: any } ? {} : import("undici-types").MessageEvent;
10
11
  type _RequestInit = typeof globalThis extends { onmessage: any } ? {}
11
12
  : import("undici-types").RequestInit;
12
13
  type _ResponseInit = typeof globalThis extends { onmessage: any } ? {}
13
14
  : import("undici-types").ResponseInit;
14
- type _File = typeof globalThis extends { onmessage: any } ? {} : import("node:buffer").File;
15
15
  // #endregion Fetch and friends
16
16
 
17
+ // #region DOMException
18
+ type _DOMException = typeof globalThis extends { onmessage: any } ? {} : NodeDOMException;
19
+ interface NodeDOMException extends Error {
20
+ /**
21
+ * @deprecated
22
+ *
23
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/DOMException/code)
24
+ */
25
+ readonly code: number;
26
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/DOMException/message) */
27
+ readonly message: string;
28
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/DOMException/name) */
29
+ readonly name: string;
30
+ readonly INDEX_SIZE_ERR: 1;
31
+ readonly DOMSTRING_SIZE_ERR: 2;
32
+ readonly HIERARCHY_REQUEST_ERR: 3;
33
+ readonly WRONG_DOCUMENT_ERR: 4;
34
+ readonly INVALID_CHARACTER_ERR: 5;
35
+ readonly NO_DATA_ALLOWED_ERR: 6;
36
+ readonly NO_MODIFICATION_ALLOWED_ERR: 7;
37
+ readonly NOT_FOUND_ERR: 8;
38
+ readonly NOT_SUPPORTED_ERR: 9;
39
+ readonly INUSE_ATTRIBUTE_ERR: 10;
40
+ readonly INVALID_STATE_ERR: 11;
41
+ readonly SYNTAX_ERR: 12;
42
+ readonly INVALID_MODIFICATION_ERR: 13;
43
+ readonly NAMESPACE_ERR: 14;
44
+ readonly INVALID_ACCESS_ERR: 15;
45
+ readonly VALIDATION_ERR: 16;
46
+ readonly TYPE_MISMATCH_ERR: 17;
47
+ readonly SECURITY_ERR: 18;
48
+ readonly NETWORK_ERR: 19;
49
+ readonly ABORT_ERR: 20;
50
+ readonly URL_MISMATCH_ERR: 21;
51
+ readonly QUOTA_EXCEEDED_ERR: 22;
52
+ readonly TIMEOUT_ERR: 23;
53
+ readonly INVALID_NODE_TYPE_ERR: 24;
54
+ readonly DATA_CLONE_ERR: 25;
55
+ }
56
+ interface NodeDOMExceptionConstructor {
57
+ prototype: DOMException;
58
+ new(message?: string, nameOrOptions?: string | { name?: string; cause?: unknown }): DOMException;
59
+ readonly INDEX_SIZE_ERR: 1;
60
+ readonly DOMSTRING_SIZE_ERR: 2;
61
+ readonly HIERARCHY_REQUEST_ERR: 3;
62
+ readonly WRONG_DOCUMENT_ERR: 4;
63
+ readonly INVALID_CHARACTER_ERR: 5;
64
+ readonly NO_DATA_ALLOWED_ERR: 6;
65
+ readonly NO_MODIFICATION_ALLOWED_ERR: 7;
66
+ readonly NOT_FOUND_ERR: 8;
67
+ readonly NOT_SUPPORTED_ERR: 9;
68
+ readonly INUSE_ATTRIBUTE_ERR: 10;
69
+ readonly INVALID_STATE_ERR: 11;
70
+ readonly SYNTAX_ERR: 12;
71
+ readonly INVALID_MODIFICATION_ERR: 13;
72
+ readonly NAMESPACE_ERR: 14;
73
+ readonly INVALID_ACCESS_ERR: 15;
74
+ readonly VALIDATION_ERR: 16;
75
+ readonly TYPE_MISMATCH_ERR: 17;
76
+ readonly SECURITY_ERR: 18;
77
+ readonly NETWORK_ERR: 19;
78
+ readonly ABORT_ERR: 20;
79
+ readonly URL_MISMATCH_ERR: 21;
80
+ readonly QUOTA_EXCEEDED_ERR: 22;
81
+ readonly TIMEOUT_ERR: 23;
82
+ readonly INVALID_NODE_TYPE_ERR: 24;
83
+ readonly DATA_CLONE_ERR: 25;
84
+ }
85
+ // #endregion DOMException
86
+
17
87
  declare global {
18
88
  // Declare "static" methods in Error
19
89
  interface ErrorConstructor {
@@ -157,6 +227,24 @@ declare global {
157
227
  transfer?: { transfer: ReadonlyArray<import("worker_threads").TransferListItem> },
158
228
  ): T;
159
229
 
230
+ // #region DOMException
231
+ /**
232
+ * @since v17.0.0
233
+ * An abnormal event (called an exception) which occurs as a result of calling a method or accessing a property of a web API.
234
+ *
235
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/DOMException)
236
+ */
237
+ interface DOMException extends _DOMException {}
238
+
239
+ /**
240
+ * @since v17.0.0
241
+ *
242
+ * The WHATWG `DOMException` class. See [DOMException](https://developer.mozilla.org/docs/Web/API/DOMException) for more details.
243
+ */
244
+ var DOMException: typeof globalThis extends { onmessage: any; DOMException: infer T } ? T
245
+ : NodeDOMExceptionConstructor;
246
+ // #endregion DOMException
247
+
160
248
  /*----------------------------------------------*
161
249
  * *
162
250
  * GLOBAL INTERFACES *
@@ -403,10 +491,13 @@ declare global {
403
491
  } ? T
404
492
  : typeof import("undici-types").Headers;
405
493
 
406
- interface File extends _File {}
407
- var File: typeof globalThis extends {
494
+ interface MessageEvent extends _MessageEvent {}
495
+ /**
496
+ * @since v15.0.0
497
+ */
498
+ var MessageEvent: typeof globalThis extends {
408
499
  onmessage: any;
409
- File: infer T;
500
+ MessageEvent: infer T;
410
501
  } ? T
411
- : typeof import("node:buffer").File;
502
+ : typeof import("undici-types").MessageEvent;
412
503
  }
node v20.16/http.d.ts CHANGED
@@ -231,7 +231,7 @@ declare module "http" {
231
231
  }
232
232
  interface ServerOptions<
233
233
  Request extends typeof IncomingMessage = typeof IncomingMessage,
234
- Response extends typeof ServerResponse = typeof ServerResponse,
234
+ Response extends typeof ServerResponse<InstanceType<Request>> = typeof ServerResponse<InstanceType<Request>>,
235
235
  > {
236
236
  /**
237
237
  * Specifies the `IncomingMessage` class to be used. Useful for extending the original `IncomingMessage`.
@@ -315,14 +315,14 @@ declare module "http" {
315
315
  }
316
316
  type RequestListener<
317
317
  Request extends typeof IncomingMessage = typeof IncomingMessage,
318
- Response extends typeof ServerResponse = typeof ServerResponse,
318
+ Response extends typeof ServerResponse<InstanceType<Request>> = typeof ServerResponse<InstanceType<Request>>,
319
319
  > = (req: InstanceType<Request>, res: InstanceType<Response> & { req: InstanceType<Request> }) => void;
320
320
  /**
321
321
  * @since v0.1.17
322
322
  */
323
323
  class Server<
324
324
  Request extends typeof IncomingMessage = typeof IncomingMessage,
325
- Response extends typeof ServerResponse = typeof ServerResponse,
325
+ Response extends typeof ServerResponse<InstanceType<Request>> = typeof ServerResponse<InstanceType<Request>>,
326
326
  > extends NetServer {
327
327
  constructor(requestListener?: RequestListener<Request, Response>);
328
328
  constructor(options: ServerOptions<Request, Response>, requestListener?: RequestListener<Request, Response>);
@@ -1553,11 +1553,11 @@ declare module "http" {
1553
1553
  */
1554
1554
  function createServer<
1555
1555
  Request extends typeof IncomingMessage = typeof IncomingMessage,
1556
- Response extends typeof ServerResponse = typeof ServerResponse,
1556
+ Response extends typeof ServerResponse<InstanceType<Request>> = typeof ServerResponse<InstanceType<Request>>,
1557
1557
  >(requestListener?: RequestListener<Request, Response>): Server<Request, Response>;
1558
1558
  function createServer<
1559
1559
  Request extends typeof IncomingMessage = typeof IncomingMessage,
1560
- Response extends typeof ServerResponse = typeof ServerResponse,
1560
+ Response extends typeof ServerResponse<InstanceType<Request>> = typeof ServerResponse<InstanceType<Request>>,
1561
1561
  >(
1562
1562
  options: ServerOptions<Request, Response>,
1563
1563
  requestListener?: RequestListener<Request, Response>,
node v20.16/http2.d.ts CHANGED
@@ -408,9 +408,9 @@ declare module "http2" {
408
408
  * });
409
409
  * ```
410
410
  *
411
- * Initiates a response. When the `options.waitForTrailers` option is set, the`'wantTrailers'` event will be emitted immediately after queuing the last chunk
412
- * of payload data to be sent. The `http2stream.sendTrailers()` method can then be
413
- * used to sent trailing header fields to the peer.
411
+ * Initiates a response. When the `options.waitForTrailers` option is set, the `'wantTrailers'` event
412
+ * will be emitted immediately after queuing the last chunk of payload data to be sent.
413
+ * The `http2stream.sendTrailers()` method can then be used to send trailing header fields to the peer.
414
414
  *
415
415
  * When `options.waitForTrailers` is set, the `Http2Stream` will not automatically
416
416
  * close when the final `DATA` frame is transmitted. User code must call either `http2stream.sendTrailers()` or `http2stream.close()` to close the `Http2Stream`.
@@ -459,8 +459,8 @@ declare module "http2" {
459
459
  *
460
460
  * The optional `options.statCheck` function may be specified to give user code
461
461
  * an opportunity to set additional content headers based on the `fs.Stat` details
462
- * of the given fd. If the `statCheck` function is provided, the `http2stream.respondWithFD()` method will perform an `fs.fstat()` call to
463
- * collect details on the provided file descriptor.
462
+ * of the given fd. If the `statCheck` function is provided, the `http2stream.respondWithFD()` method will
463
+ * perform an `fs.fstat()` call to collect details on the provided file descriptor.
464
464
  *
465
465
  * The `offset` and `length` options may be used to limit the response to a
466
466
  * specific range subset. This can be used, for instance, to support HTTP Range
@@ -478,7 +478,8 @@ declare module "http2" {
478
478
  * header fields to the peer.
479
479
  *
480
480
  * When `options.waitForTrailers` is set, the `Http2Stream` will not automatically
481
- * close when the final `DATA` frame is transmitted. User code _must_ call either `http2stream.sendTrailers()` or `http2stream.close()` to close the `Http2Stream`.
481
+ * close when the final `DATA` frame is transmitted. User code _must_ call either `http2stream.sendTrailers()`
482
+ * or `http2stream.close()` to close the `Http2Stream`.
482
483
  *
483
484
  * ```js
484
485
  * const http2 = require('node:http2');
@@ -521,9 +522,9 @@ declare module "http2" {
521
522
  * an opportunity to set additional content headers based on the `fs.Stat` details
522
523
  * of the given file:
523
524
  *
524
- * If an error occurs while attempting to read the file data, the `Http2Stream` will be closed using an `RST_STREAM` frame using the standard `INTERNAL_ERROR` code. If the `onError` callback is
525
- * defined, then it will be called. Otherwise
526
- * the stream will be destroyed.
525
+ * If an error occurs while attempting to read the file data, the `Http2Stream` will be closed using an
526
+ * `RST_STREAM` frame using the standard `INTERNAL_ERROR` code.
527
+ * If the `onError` callback is defined, then it will be called. Otherwise, the stream will be destroyed.
527
528
  *
528
529
  * Example using a file path:
529
530
  *
@@ -677,7 +678,8 @@ declare module "http2" {
677
678
  */
678
679
  readonly encrypted?: boolean | undefined;
679
680
  /**
680
- * A prototype-less object describing the current local settings of this `Http2Session`. The local settings are local to _this_`Http2Session` instance.
681
+ * A prototype-less object describing the current local settings of this `Http2Session`.
682
+ * The local settings are local to _this_`Http2Session` instance.
681
683
  * @since v8.4.0
682
684
  */
683
685
  readonly localSettings: Settings;
@@ -692,12 +694,14 @@ declare module "http2" {
692
694
  readonly originSet?: string[] | undefined;
693
695
  /**
694
696
  * Indicates whether the `Http2Session` is currently waiting for acknowledgment of
695
- * a sent `SETTINGS` frame. Will be `true` after calling the `http2session.settings()` method. Will be `false` once all sent `SETTINGS` frames have been acknowledged.
697
+ * a sent `SETTINGS` frame. Will be `true` after calling the `http2session.settings()` method.
698
+ * Will be `false` once all sent `SETTINGS` frames have been acknowledged.
696
699
  * @since v8.4.0
697
700
  */
698
701
  readonly pendingSettingsAck: boolean;
699
702
  /**
700
- * A prototype-less object describing the current remote settings of this`Http2Session`. The remote settings are set by the _connected_ HTTP/2 peer.
703
+ * A prototype-less object describing the current remote settings of this`Http2Session`.
704
+ * The remote settings are set by the _connected_ HTTP/2 peer.
701
705
  * @since v8.4.0
702
706
  */
703
707
  readonly remoteSettings: Settings;
@@ -1048,8 +1052,19 @@ declare module "http2" {
1048
1052
  export interface AlternativeServiceOptions {
1049
1053
  origin: number | string | url.URL;
1050
1054
  }
1051
- export interface ServerHttp2Session extends Http2Session {
1052
- readonly server: Http2Server | Http2SecureServer;
1055
+ export interface ServerHttp2Session<
1056
+ Http1Request extends typeof IncomingMessage = typeof IncomingMessage,
1057
+ Http1Response extends typeof ServerResponse<InstanceType<Http1Request>> = typeof ServerResponse<
1058
+ InstanceType<Http1Request>
1059
+ >,
1060
+ Http2Request extends typeof Http2ServerRequest = typeof Http2ServerRequest,
1061
+ Http2Response extends typeof Http2ServerResponse<InstanceType<Http2Request>> = typeof Http2ServerResponse<
1062
+ InstanceType<Http2Request>
1063
+ >,
1064
+ > extends Http2Session {
1065
+ readonly server:
1066
+ | Http2Server<Http1Request, Http1Response, Http2Request, Http2Response>
1067
+ | Http2SecureServer<Http1Request, Http1Response, Http2Request, Http2Response>;
1053
1068
  /**
1054
1069
  * Submits an `ALTSVC` frame (as defined by [RFC 7838](https://tools.ietf.org/html/rfc7838)) to the connected client.
1055
1070
  *
@@ -1144,17 +1159,30 @@ declare module "http2" {
1144
1159
  ): void;
1145
1160
  addListener(
1146
1161
  event: "connect",
1147
- listener: (session: ServerHttp2Session, socket: net.Socket | tls.TLSSocket) => void,
1162
+ listener: (
1163
+ session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>,
1164
+ socket: net.Socket | tls.TLSSocket,
1165
+ ) => void,
1148
1166
  ): this;
1149
1167
  addListener(
1150
1168
  event: "stream",
1151
1169
  listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void,
1152
1170
  ): this;
1153
1171
  addListener(event: string | symbol, listener: (...args: any[]) => void): this;
1154
- emit(event: "connect", session: ServerHttp2Session, socket: net.Socket | tls.TLSSocket): boolean;
1172
+ emit(
1173
+ event: "connect",
1174
+ session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>,
1175
+ socket: net.Socket | tls.TLSSocket,
1176
+ ): boolean;
1155
1177
  emit(event: "stream", stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number): boolean;
1156
1178
  emit(event: string | symbol, ...args: any[]): boolean;
1157
- on(event: "connect", listener: (session: ServerHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
1179
+ on(
1180
+ event: "connect",
1181
+ listener: (
1182
+ session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>,
1183
+ socket: net.Socket | tls.TLSSocket,
1184
+ ) => void,
1185
+ ): this;
1158
1186
  on(
1159
1187
  event: "stream",
1160
1188
  listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void,
@@ -1162,7 +1190,10 @@ declare module "http2" {
1162
1190
  on(event: string | symbol, listener: (...args: any[]) => void): this;
1163
1191
  once(
1164
1192
  event: "connect",
1165
- listener: (session: ServerHttp2Session, socket: net.Socket | tls.TLSSocket) => void,
1193
+ listener: (
1194
+ session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>,
1195
+ socket: net.Socket | tls.TLSSocket,
1196
+ ) => void,
1166
1197
  ): this;
1167
1198
  once(
1168
1199
  event: "stream",
@@ -1171,7 +1202,10 @@ declare module "http2" {
1171
1202
  once(event: string | symbol, listener: (...args: any[]) => void): this;
1172
1203
  prependListener(
1173
1204
  event: "connect",
1174
- listener: (session: ServerHttp2Session, socket: net.Socket | tls.TLSSocket) => void,
1205
+ listener: (
1206
+ session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>,
1207
+ socket: net.Socket | tls.TLSSocket,
1208
+ ) => void,
1175
1209
  ): this;
1176
1210
  prependListener(
1177
1211
  event: "stream",
@@ -1180,7 +1214,10 @@ declare module "http2" {
1180
1214
  prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
1181
1215
  prependOnceListener(
1182
1216
  event: "connect",
1183
- listener: (session: ServerHttp2Session, socket: net.Socket | tls.TLSSocket) => void,
1217
+ listener: (
1218
+ session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>,
1219
+ socket: net.Socket | tls.TLSSocket,
1220
+ ) => void,
1184
1221
  ): this;
1185
1222
  prependOnceListener(
1186
1223
  event: "stream",
@@ -1213,16 +1250,52 @@ declare module "http2" {
1213
1250
  createConnection?: ((authority: url.URL, option: SessionOptions) => stream.Duplex) | undefined;
1214
1251
  protocol?: "http:" | "https:" | undefined;
1215
1252
  }
1216
- export interface ServerSessionOptions extends SessionOptions {
1217
- Http1IncomingMessage?: typeof IncomingMessage | undefined;
1218
- Http1ServerResponse?: typeof ServerResponse | undefined;
1219
- Http2ServerRequest?: typeof Http2ServerRequest | undefined;
1220
- Http2ServerResponse?: typeof Http2ServerResponse | undefined;
1253
+ export interface ServerSessionOptions<
1254
+ Http1Request extends typeof IncomingMessage = typeof IncomingMessage,
1255
+ Http1Response extends typeof ServerResponse<InstanceType<Http1Request>> = typeof ServerResponse<
1256
+ InstanceType<Http1Request>
1257
+ >,
1258
+ Http2Request extends typeof Http2ServerRequest = typeof Http2ServerRequest,
1259
+ Http2Response extends typeof Http2ServerResponse<InstanceType<Http2Request>> = typeof Http2ServerResponse<
1260
+ InstanceType<Http2Request>
1261
+ >,
1262
+ > extends SessionOptions {
1263
+ Http1IncomingMessage?: Http1Request | undefined;
1264
+ Http1ServerResponse?: Http1Response | undefined;
1265
+ Http2ServerRequest?: Http2Request | undefined;
1266
+ Http2ServerResponse?: Http2Response | undefined;
1221
1267
  }
1222
1268
  export interface SecureClientSessionOptions extends ClientSessionOptions, tls.ConnectionOptions {}
1223
- export interface SecureServerSessionOptions extends ServerSessionOptions, tls.TlsOptions {}
1224
- export interface ServerOptions extends ServerSessionOptions {}
1225
- export interface SecureServerOptions extends SecureServerSessionOptions {
1269
+ export interface SecureServerSessionOptions<
1270
+ Http1Request extends typeof IncomingMessage = typeof IncomingMessage,
1271
+ Http1Response extends typeof ServerResponse<InstanceType<Http1Request>> = typeof ServerResponse<
1272
+ InstanceType<Http1Request>
1273
+ >,
1274
+ Http2Request extends typeof Http2ServerRequest = typeof Http2ServerRequest,
1275
+ Http2Response extends typeof Http2ServerResponse<InstanceType<Http2Request>> = typeof Http2ServerResponse<
1276
+ InstanceType<Http2Request>
1277
+ >,
1278
+ > extends ServerSessionOptions<Http1Request, Http1Response, Http2Request, Http2Response>, tls.TlsOptions {}
1279
+ export interface ServerOptions<
1280
+ Http1Request extends typeof IncomingMessage = typeof IncomingMessage,
1281
+ Http1Response extends typeof ServerResponse<InstanceType<Http1Request>> = typeof ServerResponse<
1282
+ InstanceType<Http1Request>
1283
+ >,
1284
+ Http2Request extends typeof Http2ServerRequest = typeof Http2ServerRequest,
1285
+ Http2Response extends typeof Http2ServerResponse<InstanceType<Http2Request>> = typeof Http2ServerResponse<
1286
+ InstanceType<Http2Request>
1287
+ >,
1288
+ > extends ServerSessionOptions<Http1Request, Http1Response, Http2Request, Http2Response> {}
1289
+ export interface SecureServerOptions<
1290
+ Http1Request extends typeof IncomingMessage = typeof IncomingMessage,
1291
+ Http1Response extends typeof ServerResponse<InstanceType<Http1Request>> = typeof ServerResponse<
1292
+ InstanceType<Http1Request>
1293
+ >,
1294
+ Http2Request extends typeof Http2ServerRequest = typeof Http2ServerRequest,
1295
+ Http2Response extends typeof Http2ServerResponse<InstanceType<Http2Request>> = typeof Http2ServerResponse<
1296
+ InstanceType<Http2Request>
1297
+ >,
1298
+ > extends SecureServerSessionOptions<Http1Request, Http1Response, Http2Request, Http2Response> {
1226
1299
  allowHTTP1?: boolean | undefined;
1227
1300
  origins?: string[] | undefined;
1228
1301
  }
@@ -1234,16 +1307,28 @@ declare module "http2" {
1234
1307
  */
1235
1308
  updateSettings(settings: Settings): void;
1236
1309
  }
1237
- export interface Http2Server extends net.Server, HTTP2ServerCommon {
1310
+ export interface Http2Server<
1311
+ Http1Request extends typeof IncomingMessage = typeof IncomingMessage,
1312
+ Http1Response extends typeof ServerResponse<InstanceType<Http1Request>> = typeof ServerResponse<
1313
+ InstanceType<Http1Request>
1314
+ >,
1315
+ Http2Request extends typeof Http2ServerRequest = typeof Http2ServerRequest,
1316
+ Http2Response extends typeof Http2ServerResponse<InstanceType<Http2Request>> = typeof Http2ServerResponse<
1317
+ InstanceType<Http2Request>
1318
+ >,
1319
+ > extends net.Server, HTTP2ServerCommon {
1238
1320
  addListener(
1239
1321
  event: "checkContinue",
1240
- listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void,
1322
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1241
1323
  ): this;
1242
1324
  addListener(
1243
1325
  event: "request",
1244
- listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void,
1326
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1327
+ ): this;
1328
+ addListener(
1329
+ event: "session",
1330
+ listener: (session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>) => void,
1245
1331
  ): this;
1246
- addListener(event: "session", listener: (session: ServerHttp2Session) => void): this;
1247
1332
  addListener(event: "sessionError", listener: (err: Error) => void): this;
1248
1333
  addListener(
1249
1334
  event: "stream",
@@ -1251,19 +1336,32 @@ declare module "http2" {
1251
1336
  ): this;
1252
1337
  addListener(event: "timeout", listener: () => void): this;
1253
1338
  addListener(event: string | symbol, listener: (...args: any[]) => void): this;
1254
- emit(event: "checkContinue", request: Http2ServerRequest, response: Http2ServerResponse): boolean;
1255
- emit(event: "request", request: Http2ServerRequest, response: Http2ServerResponse): boolean;
1256
- emit(event: "session", session: ServerHttp2Session): boolean;
1339
+ emit(
1340
+ event: "checkContinue",
1341
+ request: InstanceType<Http2Request>,
1342
+ response: InstanceType<Http2Response>,
1343
+ ): boolean;
1344
+ emit(event: "request", request: InstanceType<Http2Request>, response: InstanceType<Http2Response>): boolean;
1345
+ emit(
1346
+ event: "session",
1347
+ session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>,
1348
+ ): boolean;
1257
1349
  emit(event: "sessionError", err: Error): boolean;
1258
1350
  emit(event: "stream", stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number): boolean;
1259
1351
  emit(event: "timeout"): boolean;
1260
1352
  emit(event: string | symbol, ...args: any[]): boolean;
1261
1353
  on(
1262
1354
  event: "checkContinue",
1263
- listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void,
1355
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1356
+ ): this;
1357
+ on(
1358
+ event: "request",
1359
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1360
+ ): this;
1361
+ on(
1362
+ event: "session",
1363
+ listener: (session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>) => void,
1264
1364
  ): this;
1265
- on(event: "request", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1266
- on(event: "session", listener: (session: ServerHttp2Session) => void): this;
1267
1365
  on(event: "sessionError", listener: (err: Error) => void): this;
1268
1366
  on(
1269
1367
  event: "stream",
@@ -1273,10 +1371,16 @@ declare module "http2" {
1273
1371
  on(event: string | symbol, listener: (...args: any[]) => void): this;
1274
1372
  once(
1275
1373
  event: "checkContinue",
1276
- listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void,
1374
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1375
+ ): this;
1376
+ once(
1377
+ event: "request",
1378
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1379
+ ): this;
1380
+ once(
1381
+ event: "session",
1382
+ listener: (session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>) => void,
1277
1383
  ): this;
1278
- once(event: "request", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1279
- once(event: "session", listener: (session: ServerHttp2Session) => void): this;
1280
1384
  once(event: "sessionError", listener: (err: Error) => void): this;
1281
1385
  once(
1282
1386
  event: "stream",
@@ -1286,13 +1390,16 @@ declare module "http2" {
1286
1390
  once(event: string | symbol, listener: (...args: any[]) => void): this;
1287
1391
  prependListener(
1288
1392
  event: "checkContinue",
1289
- listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void,
1393
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1290
1394
  ): this;
1291
1395
  prependListener(
1292
1396
  event: "request",
1293
- listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void,
1397
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1398
+ ): this;
1399
+ prependListener(
1400
+ event: "session",
1401
+ listener: (session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>) => void,
1294
1402
  ): this;
1295
- prependListener(event: "session", listener: (session: ServerHttp2Session) => void): this;
1296
1403
  prependListener(event: "sessionError", listener: (err: Error) => void): this;
1297
1404
  prependListener(
1298
1405
  event: "stream",
@@ -1302,13 +1409,16 @@ declare module "http2" {
1302
1409
  prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
1303
1410
  prependOnceListener(
1304
1411
  event: "checkContinue",
1305
- listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void,
1412
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1306
1413
  ): this;
1307
1414
  prependOnceListener(
1308
1415
  event: "request",
1309
- listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void,
1416
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1417
+ ): this;
1418
+ prependOnceListener(
1419
+ event: "session",
1420
+ listener: (session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>) => void,
1310
1421
  ): this;
1311
- prependOnceListener(event: "session", listener: (session: ServerHttp2Session) => void): this;
1312
1422
  prependOnceListener(event: "sessionError", listener: (err: Error) => void): this;
1313
1423
  prependOnceListener(
1314
1424
  event: "stream",
@@ -1317,16 +1427,28 @@ declare module "http2" {
1317
1427
  prependOnceListener(event: "timeout", listener: () => void): this;
1318
1428
  prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
1319
1429
  }
1320
- export interface Http2SecureServer extends tls.Server, HTTP2ServerCommon {
1430
+ export interface Http2SecureServer<
1431
+ Http1Request extends typeof IncomingMessage = typeof IncomingMessage,
1432
+ Http1Response extends typeof ServerResponse<InstanceType<Http1Request>> = typeof ServerResponse<
1433
+ InstanceType<Http1Request>
1434
+ >,
1435
+ Http2Request extends typeof Http2ServerRequest = typeof Http2ServerRequest,
1436
+ Http2Response extends typeof Http2ServerResponse<InstanceType<Http2Request>> = typeof Http2ServerResponse<
1437
+ InstanceType<Http2Request>
1438
+ >,
1439
+ > extends tls.Server, HTTP2ServerCommon {
1321
1440
  addListener(
1322
1441
  event: "checkContinue",
1323
- listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void,
1442
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1324
1443
  ): this;
1325
1444
  addListener(
1326
1445
  event: "request",
1327
- listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void,
1446
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1447
+ ): this;
1448
+ addListener(
1449
+ event: "session",
1450
+ listener: (session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>) => void,
1328
1451
  ): this;
1329
- addListener(event: "session", listener: (session: ServerHttp2Session) => void): this;
1330
1452
  addListener(event: "sessionError", listener: (err: Error) => void): this;
1331
1453
  addListener(
1332
1454
  event: "stream",
@@ -1335,9 +1457,16 @@ declare module "http2" {
1335
1457
  addListener(event: "timeout", listener: () => void): this;
1336
1458
  addListener(event: "unknownProtocol", listener: (socket: tls.TLSSocket) => void): this;
1337
1459
  addListener(event: string | symbol, listener: (...args: any[]) => void): this;
1338
- emit(event: "checkContinue", request: Http2ServerRequest, response: Http2ServerResponse): boolean;
1339
- emit(event: "request", request: Http2ServerRequest, response: Http2ServerResponse): boolean;
1340
- emit(event: "session", session: ServerHttp2Session): boolean;
1460
+ emit(
1461
+ event: "checkContinue",
1462
+ request: InstanceType<Http2Request>,
1463
+ response: InstanceType<Http2Response>,
1464
+ ): boolean;
1465
+ emit(event: "request", request: InstanceType<Http2Request>, response: InstanceType<Http2Response>): boolean;
1466
+ emit(
1467
+ event: "session",
1468
+ session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>,
1469
+ ): boolean;
1341
1470
  emit(event: "sessionError", err: Error): boolean;
1342
1471
  emit(event: "stream", stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number): boolean;
1343
1472
  emit(event: "timeout"): boolean;
@@ -1345,10 +1474,16 @@ declare module "http2" {
1345
1474
  emit(event: string | symbol, ...args: any[]): boolean;
1346
1475
  on(
1347
1476
  event: "checkContinue",
1348
- listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void,
1477
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1478
+ ): this;
1479
+ on(
1480
+ event: "request",
1481
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1482
+ ): this;
1483
+ on(
1484
+ event: "session",
1485
+ listener: (session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>) => void,
1349
1486
  ): this;
1350
- on(event: "request", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1351
- on(event: "session", listener: (session: ServerHttp2Session) => void): this;
1352
1487
  on(event: "sessionError", listener: (err: Error) => void): this;
1353
1488
  on(
1354
1489
  event: "stream",
@@ -1359,10 +1494,16 @@ declare module "http2" {
1359
1494
  on(event: string | symbol, listener: (...args: any[]) => void): this;
1360
1495
  once(
1361
1496
  event: "checkContinue",
1362
- listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void,
1497
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1498
+ ): this;
1499
+ once(
1500
+ event: "request",
1501
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1502
+ ): this;
1503
+ once(
1504
+ event: "session",
1505
+ listener: (session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>) => void,
1363
1506
  ): this;
1364
- once(event: "request", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1365
- once(event: "session", listener: (session: ServerHttp2Session) => void): this;
1366
1507
  once(event: "sessionError", listener: (err: Error) => void): this;
1367
1508
  once(
1368
1509
  event: "stream",
@@ -1373,13 +1514,16 @@ declare module "http2" {
1373
1514
  once(event: string | symbol, listener: (...args: any[]) => void): this;
1374
1515
  prependListener(
1375
1516
  event: "checkContinue",
1376
- listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void,
1517
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1377
1518
  ): this;
1378
1519
  prependListener(
1379
1520
  event: "request",
1380
- listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void,
1521
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1522
+ ): this;
1523
+ prependListener(
1524
+ event: "session",
1525
+ listener: (session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>) => void,
1381
1526
  ): this;
1382
- prependListener(event: "session", listener: (session: ServerHttp2Session) => void): this;
1383
1527
  prependListener(event: "sessionError", listener: (err: Error) => void): this;
1384
1528
  prependListener(
1385
1529
  event: "stream",
@@ -1390,13 +1534,16 @@ declare module "http2" {
1390
1534
  prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
1391
1535
  prependOnceListener(
1392
1536
  event: "checkContinue",
1393
- listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void,
1537
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1394
1538
  ): this;
1395
1539
  prependOnceListener(
1396
1540
  event: "request",
1397
- listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void,
1541
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1542
+ ): this;
1543
+ prependOnceListener(
1544
+ event: "session",
1545
+ listener: (session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>) => void,
1398
1546
  ): this;
1399
- prependOnceListener(event: "session", listener: (session: ServerHttp2Session) => void): this;
1400
1547
  prependOnceListener(event: "sessionError", listener: (err: Error) => void): this;
1401
1548
  prependOnceListener(
1402
1549
  event: "stream",
@@ -1652,7 +1799,7 @@ declare module "http2" {
1652
1799
  * passed as the second parameter to the `'request'` event.
1653
1800
  * @since v8.4.0
1654
1801
  */
1655
- export class Http2ServerResponse extends stream.Writable {
1802
+ export class Http2ServerResponse<Request extends Http2ServerRequest = Http2ServerRequest> extends stream.Writable {
1656
1803
  constructor(stream: ServerHttp2Stream);
1657
1804
  /**
1658
1805
  * See `response.socket`.
@@ -1698,7 +1845,7 @@ declare module "http2" {
1698
1845
  * A reference to the original HTTP2 `request` object.
1699
1846
  * @since v15.7.0
1700
1847
  */
1701
- readonly req: Http2ServerRequest;
1848
+ readonly req: Request;
1702
1849
  /**
1703
1850
  * Returns a `Proxy` object that acts as a `net.Socket` (or `tls.TLSSocket`) but
1704
1851
  * applies getters, setters, and methods based on HTTP/2 logic.
@@ -2341,10 +2488,19 @@ declare module "http2" {
2341
2488
  export function createServer(
2342
2489
  onRequestHandler?: (request: Http2ServerRequest, response: Http2ServerResponse) => void,
2343
2490
  ): Http2Server;
2344
- export function createServer(
2345
- options: ServerOptions,
2346
- onRequestHandler?: (request: Http2ServerRequest, response: Http2ServerResponse) => void,
2347
- ): Http2Server;
2491
+ export function createServer<
2492
+ Http1Request extends typeof IncomingMessage = typeof IncomingMessage,
2493
+ Http1Response extends typeof ServerResponse<InstanceType<Http1Request>> = typeof ServerResponse<
2494
+ InstanceType<Http1Request>
2495
+ >,
2496
+ Http2Request extends typeof Http2ServerRequest = typeof Http2ServerRequest,
2497
+ Http2Response extends typeof Http2ServerResponse<InstanceType<Http2Request>> = typeof Http2ServerResponse<
2498
+ InstanceType<Http2Request>
2499
+ >,
2500
+ >(
2501
+ options: ServerOptions<Http1Request, Http1Response, Http2Request, Http2Response>,
2502
+ onRequestHandler?: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
2503
+ ): Http2Server<Http1Request, Http1Response, Http2Request, Http2Response>;
2348
2504
  /**
2349
2505
  * Returns a `tls.Server` instance that creates and manages `Http2Session` instances.
2350
2506
  *
@@ -2376,10 +2532,19 @@ declare module "http2" {
2376
2532
  export function createSecureServer(
2377
2533
  onRequestHandler?: (request: Http2ServerRequest, response: Http2ServerResponse) => void,
2378
2534
  ): Http2SecureServer;
2379
- export function createSecureServer(
2380
- options: SecureServerOptions,
2381
- onRequestHandler?: (request: Http2ServerRequest, response: Http2ServerResponse) => void,
2382
- ): Http2SecureServer;
2535
+ export function createSecureServer<
2536
+ Http1Request extends typeof IncomingMessage = typeof IncomingMessage,
2537
+ Http1Response extends typeof ServerResponse<InstanceType<Http1Request>> = typeof ServerResponse<
2538
+ InstanceType<Http1Request>
2539
+ >,
2540
+ Http2Request extends typeof Http2ServerRequest = typeof Http2ServerRequest,
2541
+ Http2Response extends typeof Http2ServerResponse<InstanceType<Http2Request>> = typeof Http2ServerResponse<
2542
+ InstanceType<Http2Request>
2543
+ >,
2544
+ >(
2545
+ options: SecureServerOptions<Http1Request, Http1Response, Http2Request, Http2Response>,
2546
+ onRequestHandler?: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
2547
+ ): Http2SecureServer<Http1Request, Http1Response, Http2Request, Http2Response>;
2383
2548
  /**
2384
2549
  * Returns a `ClientHttp2Session` instance.
2385
2550
  *
@@ -2411,7 +2576,19 @@ declare module "http2" {
2411
2576
  * @param options Any `{@link createServer}` options can be provided.
2412
2577
  * @since v20.12.0
2413
2578
  */
2414
- export function performServerHandshake(socket: stream.Duplex, options?: ServerOptions): ServerHttp2Session;
2579
+ export function performServerHandshake<
2580
+ Http1Request extends typeof IncomingMessage = typeof IncomingMessage,
2581
+ Http1Response extends typeof ServerResponse<InstanceType<Http1Request>> = typeof ServerResponse<
2582
+ InstanceType<Http1Request>
2583
+ >,
2584
+ Http2Request extends typeof Http2ServerRequest = typeof Http2ServerRequest,
2585
+ Http2Response extends typeof Http2ServerResponse<InstanceType<Http2Request>> = typeof Http2ServerResponse<
2586
+ InstanceType<Http2Request>
2587
+ >,
2588
+ >(
2589
+ socket: stream.Duplex,
2590
+ options?: ServerOptions<Http1Request, Http1Response, Http2Request, Http2Response>,
2591
+ ): ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>;
2415
2592
  }
2416
2593
  declare module "node:http2" {
2417
2594
  export * from "http2";
node v20.16/https.d.ts CHANGED
@@ -10,7 +10,9 @@ declare module "https" {
10
10
  import { URL } from "node:url";
11
11
  type ServerOptions<
12
12
  Request extends typeof http.IncomingMessage = typeof http.IncomingMessage,
13
- Response extends typeof http.ServerResponse = typeof http.ServerResponse,
13
+ Response extends typeof http.ServerResponse<InstanceType<Request>> = typeof http.ServerResponse<
14
+ InstanceType<Request>
15
+ >,
14
16
  > = tls.SecureContextOptions & tls.TlsOptions & http.ServerOptions<Request, Response>;
15
17
  type RequestOptions =
16
18
  & http.RequestOptions
@@ -34,7 +36,9 @@ declare module "https" {
34
36
  }
35
37
  interface Server<
36
38
  Request extends typeof http.IncomingMessage = typeof http.IncomingMessage,
37
- Response extends typeof http.ServerResponse = typeof http.ServerResponse,
39
+ Response extends typeof http.ServerResponse<InstanceType<Request>> = typeof http.ServerResponse<
40
+ InstanceType<Request>
41
+ >,
38
42
  > extends http.Server<Request, Response> {}
39
43
  /**
40
44
  * See `http.Server` for more information.
@@ -42,7 +46,9 @@ declare module "https" {
42
46
  */
43
47
  class Server<
44
48
  Request extends typeof http.IncomingMessage = typeof http.IncomingMessage,
45
- Response extends typeof http.ServerResponse = typeof http.ServerResponse,
49
+ Response extends typeof http.ServerResponse<InstanceType<Request>> = typeof http.ServerResponse<
50
+ InstanceType<Request>
51
+ >,
46
52
  > extends tls.Server {
47
53
  constructor(requestListener?: http.RequestListener<Request, Response>);
48
54
  constructor(
@@ -119,25 +125,19 @@ declare module "https" {
119
125
  emit(
120
126
  event: "checkContinue",
121
127
  req: InstanceType<Request>,
122
- res: InstanceType<Response> & {
123
- req: InstanceType<Request>;
124
- },
128
+ res: InstanceType<Response>,
125
129
  ): boolean;
126
130
  emit(
127
131
  event: "checkExpectation",
128
132
  req: InstanceType<Request>,
129
- res: InstanceType<Response> & {
130
- req: InstanceType<Request>;
131
- },
133
+ res: InstanceType<Response>,
132
134
  ): boolean;
133
135
  emit(event: "clientError", err: Error, socket: Duplex): boolean;
134
136
  emit(event: "connect", req: InstanceType<Request>, socket: Duplex, head: Buffer): boolean;
135
137
  emit(
136
138
  event: "request",
137
139
  req: InstanceType<Request>,
138
- res: InstanceType<Response> & {
139
- req: InstanceType<Request>;
140
- },
140
+ res: InstanceType<Response>,
141
141
  ): boolean;
142
142
  emit(event: "upgrade", req: InstanceType<Request>, socket: Duplex, head: Buffer): boolean;
143
143
  on(event: string, listener: (...args: any[]) => void): this;
@@ -312,11 +312,15 @@ declare module "https" {
312
312
  */
313
313
  function createServer<
314
314
  Request extends typeof http.IncomingMessage = typeof http.IncomingMessage,
315
- Response extends typeof http.ServerResponse = typeof http.ServerResponse,
315
+ Response extends typeof http.ServerResponse<InstanceType<Request>> = typeof http.ServerResponse<
316
+ InstanceType<Request>
317
+ >,
316
318
  >(requestListener?: http.RequestListener<Request, Response>): Server<Request, Response>;
317
319
  function createServer<
318
320
  Request extends typeof http.IncomingMessage = typeof http.IncomingMessage,
319
- Response extends typeof http.ServerResponse = typeof http.ServerResponse,
321
+ Response extends typeof http.ServerResponse<InstanceType<Request>> = typeof http.ServerResponse<
322
+ InstanceType<Request>
323
+ >,
320
324
  >(
321
325
  options: ServerOptions<Request, Response>,
322
326
  requestListener?: http.RequestListener<Request, Response>,
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@types/node",
3
- "version": "20.16.2",
3
+ "version": "20.16.4",
4
4
  "description": "TypeScript definitions for node",
5
5
  "homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node",
6
6
  "license": "MIT",
@@ -212,6 +212,6 @@
212
212
  "dependencies": {
213
213
  "undici-types": "~6.19.2"
214
214
  },
215
- "typesPublisherContentHash": "bfa190547a4fe06159207f447a2b225d7ee753bec878cab8292ade89f64f3a06",
215
+ "typesPublisherContentHash": "10193b21f3b805f743937e27ffb934232a41b0eb535834290ae0b4f87d8699b4",
216
216
  "typeScriptVersion": "4.8"
217
217
  }
@@ -1,3 +1,38 @@
1
+ type _ByteLengthQueuingStrategy = typeof globalThis extends { onmessage: any } ? {}
2
+ : import("stream/web").ByteLengthQueuingStrategy;
3
+ type _CompressionStream = typeof globalThis extends { onmessage: any; ReportingObserver: any } ? {}
4
+ : import("stream/web").CompressionStream;
5
+ type _CountQueuingStrategy = typeof globalThis extends { onmessage: any } ? {}
6
+ : import("stream/web").CountQueuingStrategy;
7
+ type _DecompressionStream = typeof globalThis extends { onmessage: any; ReportingObserver: any } ? {}
8
+ : import("stream/web").DecompressionStream;
9
+ type _ReadableByteStreamController = typeof globalThis extends { onmessage: any } ? {}
10
+ : import("stream/web").ReadableByteStreamController;
11
+ type _ReadableStream<R = any> = typeof globalThis extends { onmessage: any } ? {}
12
+ : import("stream/web").ReadableStream<R>;
13
+ type _ReadableStreamBYOBReader = typeof globalThis extends { onmessage: any } ? {}
14
+ : import("stream/web").ReadableStreamBYOBReader;
15
+ type _ReadableStreamBYOBRequest = typeof globalThis extends { onmessage: any } ? {}
16
+ : import("stream/web").ReadableStreamBYOBRequest;
17
+ type _ReadableStreamDefaultController<R = any> = typeof globalThis extends { onmessage: any } ? {}
18
+ : import("stream/web").ReadableStreamDefaultController<R>;
19
+ type _ReadableStreamDefaultReader<R = any> = typeof globalThis extends { onmessage: any } ? {}
20
+ : import("stream/web").ReadableStreamDefaultReader<R>;
21
+ type _TextDecoderStream = typeof globalThis extends { onmessage: any } ? {}
22
+ : import("stream/web").TextDecoderStream;
23
+ type _TextEncoderStream = typeof globalThis extends { onmessage: any } ? {}
24
+ : import("stream/web").TextEncoderStream;
25
+ type _TransformStream<I = any, O = any> = typeof globalThis extends { onmessage: any } ? {}
26
+ : import("stream/web").TransformStream<I, O>;
27
+ type _TransformStreamDefaultController<O = any> = typeof globalThis extends { onmessage: any } ? {}
28
+ : import("stream/web").TransformStreamDefaultController<O>;
29
+ type _WritableStream<W = any> = typeof globalThis extends { onmessage: any } ? {}
30
+ : import("stream/web").WritableStream<W>;
31
+ type _WritableStreamDefaultController = typeof globalThis extends { onmessage: any } ? {}
32
+ : import("stream/web").WritableStreamDefaultController;
33
+ type _WritableStreamDefaultWriter<W = any> = typeof globalThis extends { onmessage: any } ? {}
34
+ : import("stream/web").WritableStreamDefaultWriter<W>;
35
+
1
36
  declare module "stream/web" {
2
37
  // stub module, pending copy&paste from .d.ts or manual impl
3
38
  // copy from lib.dom.d.ts
@@ -65,18 +100,7 @@ declare module "stream/web" {
65
100
  readonly closed: Promise<undefined>;
66
101
  cancel(reason?: any): Promise<void>;
67
102
  }
68
- interface ReadableStreamDefaultReadValueResult<T> {
69
- done: false;
70
- value: T;
71
- }
72
- interface ReadableStreamDefaultReadDoneResult {
73
- done: true;
74
- value?: undefined;
75
- }
76
103
  type ReadableStreamController<T> = ReadableStreamDefaultController<T>;
77
- type ReadableStreamDefaultReadResult<T> =
78
- | ReadableStreamDefaultReadValueResult<T>
79
- | ReadableStreamDefaultReadDoneResult;
80
104
  interface ReadableStreamReadValueResult<T> {
81
105
  done: false;
82
106
  value: T;
@@ -146,8 +170,9 @@ declare module "stream/web" {
146
170
  interface ReadableStream<R = any> {
147
171
  readonly locked: boolean;
148
172
  cancel(reason?: any): Promise<void>;
149
- getReader(): ReadableStreamDefaultReader<R>;
150
173
  getReader(options: { mode: "byob" }): ReadableStreamBYOBReader;
174
+ getReader(): ReadableStreamDefaultReader<R>;
175
+ getReader(options?: ReadableStreamGetReaderOptions): ReadableStreamReader<R>;
151
176
  pipeThrough<T>(transform: ReadableWritablePair<T, R>, options?: StreamPipeOptions): ReadableStream<T>;
152
177
  pipeTo(destination: WritableStream<R>, options?: StreamPipeOptions): Promise<void>;
153
178
  tee(): [ReadableStream<R>, ReadableStream<R>];
@@ -160,20 +185,48 @@ declare module "stream/web" {
160
185
  new(underlyingSource: UnderlyingByteSource, strategy?: QueuingStrategy<Uint8Array>): ReadableStream<Uint8Array>;
161
186
  new<R = any>(underlyingSource?: UnderlyingSource<R>, strategy?: QueuingStrategy<R>): ReadableStream<R>;
162
187
  };
188
+ type ReadableStreamReaderMode = "byob";
189
+ interface ReadableStreamGetReaderOptions {
190
+ /**
191
+ * Creates a ReadableStreamBYOBReader and locks the stream to the new reader.
192
+ *
193
+ * This call behaves the same way as the no-argument variant, except that it only works on readable byte streams, i.e. streams which were constructed specifically with the ability to handle "bring your own buffer" reading. The returned BYOB reader provides the ability to directly read individual chunks from the stream via its read() method, into developer-supplied buffers, allowing more precise control over allocation.
194
+ */
195
+ mode?: ReadableStreamReaderMode;
196
+ }
197
+ type ReadableStreamReader<T> = ReadableStreamDefaultReader<T> | ReadableStreamBYOBReader;
163
198
  interface ReadableStreamDefaultReader<R = any> extends ReadableStreamGenericReader {
164
- read(): Promise<ReadableStreamDefaultReadResult<R>>;
199
+ read(): Promise<ReadableStreamReadResult<R>>;
165
200
  releaseLock(): void;
166
201
  }
202
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader) */
167
203
  interface ReadableStreamBYOBReader extends ReadableStreamGenericReader {
204
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader/read) */
168
205
  read<T extends ArrayBufferView>(view: T): Promise<ReadableStreamReadResult<T>>;
206
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader/releaseLock) */
169
207
  releaseLock(): void;
170
208
  }
171
209
  const ReadableStreamDefaultReader: {
172
210
  prototype: ReadableStreamDefaultReader;
173
211
  new<R = any>(stream: ReadableStream<R>): ReadableStreamDefaultReader<R>;
174
212
  };
175
- const ReadableStreamBYOBReader: any;
176
- const ReadableStreamBYOBRequest: any;
213
+ const ReadableStreamBYOBReader: {
214
+ prototype: ReadableStreamBYOBReader;
215
+ new(stream: ReadableStream): ReadableStreamBYOBReader;
216
+ };
217
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBRequest) */
218
+ interface ReadableStreamBYOBRequest {
219
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBRequest/view) */
220
+ readonly view: ArrayBufferView | null;
221
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBRequest/respond) */
222
+ respond(bytesWritten: number): void;
223
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBRequest/respondWithNewView) */
224
+ respondWithNewView(view: ArrayBufferView): void;
225
+ }
226
+ const ReadableStreamBYOBRequest: {
227
+ prototype: ReadableStreamBYOBRequest;
228
+ new(): ReadableStreamBYOBRequest;
229
+ };
177
230
  interface ReadableByteStreamController {
178
231
  readonly byobRequest: undefined;
179
232
  readonly desiredSize: number | null;
@@ -345,22 +398,123 @@ declare module "stream/web" {
345
398
  prototype: TextDecoderStream;
346
399
  new(encoding?: string, options?: TextDecoderOptions): TextDecoderStream;
347
400
  };
348
- interface CompressionStream<R = any, W = any> {
349
- readonly readable: ReadableStream<R>;
350
- readonly writable: WritableStream<W>;
401
+ interface CompressionStream {
402
+ readonly readable: ReadableStream;
403
+ readonly writable: WritableStream;
351
404
  }
352
405
  const CompressionStream: {
353
406
  prototype: CompressionStream;
354
- new<R = any, W = any>(format: "deflate" | "deflate-raw" | "gzip"): CompressionStream<R, W>;
407
+ new(format: "deflate" | "deflate-raw" | "gzip"): CompressionStream;
355
408
  };
356
- interface DecompressionStream<R = any, W = any> {
357
- readonly readable: ReadableStream<R>;
358
- readonly writable: WritableStream<W>;
409
+ interface DecompressionStream {
410
+ readonly writable: WritableStream;
411
+ readonly readable: ReadableStream;
359
412
  }
360
413
  const DecompressionStream: {
361
414
  prototype: DecompressionStream;
362
- new<R = any, W = any>(format: "deflate" | "deflate-raw" | "gzip"): DecompressionStream<R, W>;
415
+ new(format: "deflate" | "deflate-raw" | "gzip"): DecompressionStream;
363
416
  };
417
+
418
+ global {
419
+ interface ByteLengthQueuingStrategy extends _ByteLengthQueuingStrategy {}
420
+ var ByteLengthQueuingStrategy: typeof globalThis extends { onmessage: any; ByteLengthQueuingStrategy: infer T }
421
+ ? T
422
+ : typeof import("stream/web").ByteLengthQueuingStrategy;
423
+
424
+ interface CompressionStream extends _CompressionStream {}
425
+ var CompressionStream: typeof globalThis extends {
426
+ onmessage: any;
427
+ // CompressionStream, DecompressionStream and ReportingObserver was introduced in the same commit.
428
+ // If ReportingObserver check is removed, the type here will form a circular reference in TS5.0+lib.dom.d.ts
429
+ ReportingObserver: any;
430
+ CompressionStream: infer T;
431
+ } ? T
432
+ // TS 4.8, 4.9, 5.0
433
+ : typeof globalThis extends { onmessage: any; TransformStream: { prototype: infer T } } ? {
434
+ prototype: T;
435
+ new(format: "deflate" | "deflate-raw" | "gzip"): T;
436
+ }
437
+ : typeof import("stream/web").CompressionStream;
438
+
439
+ interface CountQueuingStrategy extends _CountQueuingStrategy {}
440
+ var CountQueuingStrategy: typeof globalThis extends { onmessage: any; CountQueuingStrategy: infer T } ? T
441
+ : typeof import("stream/web").CountQueuingStrategy;
442
+
443
+ interface DecompressionStream extends _DecompressionStream {}
444
+ var DecompressionStream: typeof globalThis extends {
445
+ onmessage: any;
446
+ // CompressionStream, DecompressionStream and ReportingObserver was introduced in the same commit.
447
+ // If ReportingObserver check is removed, the type here will form a circular reference in TS5.0+lib.dom.d.ts
448
+ ReportingObserver: any;
449
+ DecompressionStream: infer T;
450
+ } ? T
451
+ // TS 4.8, 4.9, 5.0
452
+ : typeof globalThis extends { onmessage: any; TransformStream: { prototype: infer T } } ? {
453
+ prototype: T;
454
+ new(format: "deflate" | "deflate-raw" | "gzip"): T;
455
+ }
456
+ : typeof import("stream/web").DecompressionStream;
457
+
458
+ interface ReadableByteStreamController extends _ReadableByteStreamController {}
459
+ var ReadableByteStreamController: typeof globalThis extends
460
+ { onmessage: any; ReadableByteStreamController: infer T } ? T
461
+ : typeof import("stream/web").ReadableByteStreamController;
462
+
463
+ interface ReadableStream<R = any> extends _ReadableStream<R> {}
464
+ var ReadableStream: typeof globalThis extends { onmessage: any; ReadableStream: infer T } ? T
465
+ : typeof import("stream/web").ReadableStream;
466
+
467
+ interface ReadableStreamBYOBReader extends _ReadableStreamBYOBReader {}
468
+ var ReadableStreamBYOBReader: typeof globalThis extends { onmessage: any; ReadableStreamBYOBReader: infer T }
469
+ ? T
470
+ : typeof import("stream/web").ReadableStreamBYOBReader;
471
+
472
+ interface ReadableStreamBYOBRequest extends _ReadableStreamBYOBRequest {}
473
+ var ReadableStreamBYOBRequest: typeof globalThis extends { onmessage: any; ReadableStreamBYOBRequest: infer T }
474
+ ? T
475
+ : typeof import("stream/web").ReadableStreamBYOBRequest;
476
+
477
+ interface ReadableStreamDefaultController<R = any> extends _ReadableStreamDefaultController<R> {}
478
+ var ReadableStreamDefaultController: typeof globalThis extends
479
+ { onmessage: any; ReadableStreamDefaultController: infer T } ? T
480
+ : typeof import("stream/web").ReadableStreamDefaultController;
481
+
482
+ interface ReadableStreamDefaultReader<R = any> extends _ReadableStreamDefaultReader<R> {}
483
+ var ReadableStreamDefaultReader: typeof globalThis extends
484
+ { onmessage: any; ReadableStreamDefaultReader: infer T } ? T
485
+ : typeof import("stream/web").ReadableStreamDefaultReader;
486
+
487
+ interface TextDecoderStream extends _TextDecoderStream {}
488
+ var TextDecoderStream: typeof globalThis extends { onmessage: any; TextDecoderStream: infer T } ? T
489
+ : typeof import("stream/web").TextDecoderStream;
490
+
491
+ interface TextEncoderStream extends _TextEncoderStream {}
492
+ var TextEncoderStream: typeof globalThis extends { onmessage: any; TextEncoderStream: infer T } ? T
493
+ : typeof import("stream/web").TextEncoderStream;
494
+
495
+ interface TransformStream<I = any, O = any> extends _TransformStream<I, O> {}
496
+ var TransformStream: typeof globalThis extends { onmessage: any; TransformStream: infer T } ? T
497
+ : typeof import("stream/web").TransformStream;
498
+
499
+ interface TransformStreamDefaultController<O = any> extends _TransformStreamDefaultController<O> {}
500
+ var TransformStreamDefaultController: typeof globalThis extends
501
+ { onmessage: any; TransformStreamDefaultController: infer T } ? T
502
+ : typeof import("stream/web").TransformStreamDefaultController;
503
+
504
+ interface WritableStream<W = any> extends _WritableStream<W> {}
505
+ var WritableStream: typeof globalThis extends { onmessage: any; WritableStream: infer T } ? T
506
+ : typeof import("stream/web").WritableStream;
507
+
508
+ interface WritableStreamDefaultController extends _WritableStreamDefaultController {}
509
+ var WritableStreamDefaultController: typeof globalThis extends
510
+ { onmessage: any; WritableStreamDefaultController: infer T } ? T
511
+ : typeof import("stream/web").WritableStreamDefaultController;
512
+
513
+ interface WritableStreamDefaultWriter<W = any> extends _WritableStreamDefaultWriter<W> {}
514
+ var WritableStreamDefaultWriter: typeof globalThis extends
515
+ { onmessage: any; WritableStreamDefaultWriter: infer T } ? T
516
+ : typeof import("stream/web").WritableStreamDefaultWriter;
517
+ }
364
518
  }
365
519
  declare module "node:stream/web" {
366
520
  export * from "stream/web";
node v20.16/test.d.ts CHANGED
@@ -460,32 +460,36 @@ declare module "node:test" {
460
460
  readonly assert: TestContextAssert;
461
461
  /**
462
462
  * This function is used to create a hook running before subtest of the current test.
463
- * @param fn The hook function. If the hook uses callbacks, the callback function is passed as the second argument.
463
+ * @param fn The hook function. The first argument to this function is a `TestContext` object.
464
+ * If the hook uses callbacks, the callback function is passed as the second argument.
464
465
  * @param options Configuration options for the hook.
465
- * @since v20.1.0
466
+ * @since v20.1.0, v18.17.0
466
467
  */
467
- before: typeof before;
468
+ before(fn?: TestContextHookFn, options?: HookOptions): void;
468
469
  /**
469
470
  * This function is used to create a hook running before each subtest of the current test.
470
- * @param fn The hook function. If the hook uses callbacks, the callback function is passed as the second argument.
471
+ * @param fn The hook function. The first argument to this function is a `TestContext` object.
472
+ * If the hook uses callbacks, the callback function is passed as the second argument.
471
473
  * @param options Configuration options for the hook.
472
474
  * @since v18.8.0
473
475
  */
474
- beforeEach: typeof beforeEach;
476
+ beforeEach(fn?: TestContextHookFn, options?: HookOptions): void;
475
477
  /**
476
478
  * This function is used to create a hook that runs after the current test finishes.
477
- * @param fn The hook function. If the hook uses callbacks, the callback function is passed as the second argument.
479
+ * @param fn The hook function. The first argument to this function is a `TestContext` object.
480
+ * If the hook uses callbacks, the callback function is passed as the second argument.
478
481
  * @param options Configuration options for the hook.
479
482
  * @since v18.13.0
480
483
  */
481
- after: typeof after;
484
+ after(fn?: TestContextHookFn, options?: HookOptions): void;
482
485
  /**
483
486
  * This function is used to create a hook running after each subtest of the current test.
484
- * @param fn The hook function. If the hook uses callbacks, the callback function is passed as the second argument.
487
+ * @param fn The hook function. The first argument to this function is a `TestContext` object.
488
+ * If the hook uses callbacks, the callback function is passed as the second argument.
485
489
  * @param options Configuration options for the hook.
486
490
  * @since v18.8.0
487
491
  */
488
- afterEach: typeof afterEach;
492
+ afterEach(fn?: TestContextHookFn, options?: HookOptions): void;
489
493
  /**
490
494
  * This function is used to write diagnostics to the output. Any diagnostic
491
495
  * information is included at the end of the test's results. This function does
@@ -826,10 +830,15 @@ declare module "node:test" {
826
830
  */
827
831
  function afterEach(fn?: HookFn, options?: HookOptions): void;
828
832
  /**
829
- * The hook function. If the hook uses callbacks, the callback function is passed as the
830
- * second argument.
833
+ * The hook function. The first argument is the context in which the hook is called.
834
+ * If the hook uses callbacks, the callback function is passed as the second argument.
831
835
  */
832
- type HookFn = (s: SuiteContext, done: (result?: any) => void) => any;
836
+ type HookFn = (c: TestContext | SuiteContext, done: (result?: any) => void) => any;
837
+ /**
838
+ * The hook function. The first argument is a `TestContext` object.
839
+ * If the hook uses callbacks, the callback function is passed as the second argument.
840
+ */
841
+ type TestContextHookFn = (t: TestContext, done: (result?: any) => void) => any;
833
842
  /**
834
843
  * Configuration options for hooks.
835
844
  * @since v18.8.0