@types/node 22.15.21 → 22.19.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. node v22.19/README.md +15 -0
  2. node v22.19/assert/strict.d.ts +111 -0
  3. node/assert.d.ts → node v22.19/assert.d.ts +119 -95
  4. node/buffer.buffer.d.ts → node v22.19/buffer.buffer.d.ts +9 -0
  5. node/buffer.d.ts → node v22.19/buffer.d.ts +14 -6
  6. node/child_process.d.ts → node v22.19/child_process.d.ts +89 -162
  7. node/cluster.d.ts → node v22.19/cluster.d.ts +4 -5
  8. node/compatibility/disposable.d.ts → node v22.19/compatibility/disposable.d.ts +0 -2
  9. node/compatibility/indexable.d.ts → node v22.19/compatibility/indexable.d.ts +0 -3
  10. node/compatibility/iterators.d.ts → node v22.19/compatibility/iterators.d.ts +0 -1
  11. node/crypto.d.ts → node v22.19/crypto.d.ts +203 -167
  12. node/dgram.d.ts → node v22.19/dgram.d.ts +9 -8
  13. node/diagnostics_channel.d.ts → node v22.19/diagnostics_channel.d.ts +17 -12
  14. node/dns/promises.d.ts → node v22.19/dns/promises.d.ts +36 -9
  15. node/dns.d.ts → node v22.19/dns.d.ts +79 -21
  16. node/events.d.ts → node v22.19/events.d.ts +80 -35
  17. node/fs/promises.d.ts → node v22.19/fs/promises.d.ts +81 -58
  18. node/fs.d.ts → node v22.19/fs.d.ts +154 -130
  19. node v22.19/globals.d.ts +172 -0
  20. node v22.19/globals.typedarray.d.ts +38 -0
  21. node/http.d.ts → node v22.19/http.d.ts +140 -35
  22. node/http2.d.ts → node v22.19/http2.d.ts +114 -27
  23. node/https.d.ts → node v22.19/https.d.ts +96 -62
  24. node/index.d.ts → node v22.19/index.d.ts +7 -2
  25. node v22.19/inspector.d.ts +253 -0
  26. node/inspector.d.ts → node v22.19/inspector.generated.d.ts +880 -830
  27. node/module.d.ts → node v22.19/module.d.ts +136 -17
  28. node/net.d.ts → node v22.19/net.d.ts +33 -11
  29. node/os.d.ts → node v22.19/os.d.ts +14 -3
  30. node/package.json → node v22.19/package.json +3 -83
  31. node/path.d.ts → node v22.19/path.d.ts +1 -1
  32. node/perf_hooks.d.ts → node v22.19/perf_hooks.d.ts +8 -10
  33. node/process.d.ts → node v22.19/process.d.ts +39 -27
  34. node/readline/promises.d.ts → node v22.19/readline/promises.d.ts +1 -2
  35. node/repl.d.ts → node v22.19/repl.d.ts +3 -5
  36. node/sqlite.d.ts → node v22.19/sqlite.d.ts +219 -6
  37. node/stream/consumers.d.ts → node v22.19/stream/consumers.d.ts +2 -2
  38. node/stream/web.d.ts → node v22.19/stream/web.d.ts +8 -0
  39. node/stream.d.ts → node v22.19/stream.d.ts +34 -32
  40. node/string_decoder.d.ts → node v22.19/string_decoder.d.ts +2 -2
  41. node v22.19/test.d.ts +2162 -0
  42. node/tls.d.ts → node v22.19/tls.d.ts +122 -66
  43. node/ts5.6/buffer.buffer.d.ts → node v22.19/ts5.6/buffer.buffer.d.ts +10 -2
  44. node v22.19/ts5.6/globals.typedarray.d.ts +34 -0
  45. node/ts5.6/index.d.ts → node v22.19/ts5.6/index.d.ts +7 -2
  46. node/url.d.ts → node v22.19/url.d.ts +21 -9
  47. node/util.d.ts → node v22.19/util.d.ts +33 -11
  48. node/v8.d.ts → node v22.19/v8.d.ts +66 -35
  49. node/vm.d.ts → node v22.19/vm.d.ts +65 -56
  50. node/wasi.d.ts → node v22.19/wasi.d.ts +1 -1
  51. node v22.19/web-globals/abortcontroller.d.ts +34 -0
  52. node v22.19/web-globals/domexception.d.ts +68 -0
  53. node v22.19/web-globals/events.d.ts +97 -0
  54. node v22.19/web-globals/fetch.d.ts +46 -0
  55. node v22.19/web-globals/navigator.d.ts +22 -0
  56. node v22.19/web-globals/storage.d.ts +24 -0
  57. node/worker_threads.d.ts → node v22.19/worker_threads.d.ts +112 -74
  58. node/zlib.d.ts → node v22.19/zlib.d.ts +39 -26
  59. node/README.md +0 -15
  60. node/assert/strict.d.ts +0 -8
  61. node/dom-events.d.ts +0 -124
  62. node/globals.d.ts +0 -371
  63. node/globals.typedarray.d.ts +0 -21
  64. node/test.d.ts +0 -2280
  65. node/ts5.6/globals.typedarray.d.ts +0 -19
  66. {node → node v22.19}/LICENSE +0 -0
  67. node/async_hooks.d.ts → node v22.19/async_hooks.d.ts +1 -1
  68. {node → node v22.19}/compatibility/index.d.ts +0 -0
  69. {node → node v22.19}/console.d.ts +0 -0
  70. {node → node v22.19}/constants.d.ts +0 -0
  71. {node → node v22.19}/domain.d.ts +0 -0
  72. {node → node v22.19}/punycode.d.ts +0 -0
  73. {node → node v22.19}/querystring.d.ts +0 -0
  74. {node → node v22.19}/readline.d.ts +0 -0
  75. {node → node v22.19}/sea.d.ts +0 -0
  76. {node → node v22.19}/stream/promises.d.ts +0 -0
  77. {node → node v22.19}/timers/promises.d.ts +0 -0
  78. {node → node v22.19}/timers.d.ts +0 -0
  79. {node → node v22.19}/trace_events.d.ts +0 -0
  80. {node → node v22.19}/tty.d.ts +0 -0
@@ -0,0 +1,97 @@
1
+ export {};
2
+
3
+ interface AddEventListenerOptions extends EventListenerOptions {
4
+ once?: boolean;
5
+ passive?: boolean;
6
+ signal?: AbortSignal;
7
+ }
8
+
9
+ type _CustomEvent<T = any> = typeof globalThis extends { onmessage: any } ? {} : CustomEvent<T>;
10
+ interface CustomEvent<T = any> extends Event {
11
+ readonly detail: T;
12
+ }
13
+
14
+ interface CustomEventInit<T = any> extends EventInit {
15
+ detail?: T;
16
+ }
17
+
18
+ type _Event = typeof globalThis extends { onmessage: any } ? {} : Event;
19
+ interface Event {
20
+ readonly bubbles: boolean;
21
+ cancelBubble: boolean;
22
+ readonly cancelable: boolean;
23
+ readonly composed: boolean;
24
+ readonly currentTarget: EventTarget | null;
25
+ readonly defaultPrevented: boolean;
26
+ readonly eventPhase: 0 | 2;
27
+ readonly isTrusted: boolean;
28
+ returnValue: boolean;
29
+ readonly srcElement: EventTarget | null;
30
+ readonly target: EventTarget | null;
31
+ readonly timeStamp: number;
32
+ readonly type: string;
33
+ composedPath(): [EventTarget?];
34
+ initEvent(type: string, bubbles?: boolean, cancelable?: boolean): void;
35
+ preventDefault(): void;
36
+ stopImmediatePropagation(): void;
37
+ stopPropagation(): void;
38
+ }
39
+
40
+ interface EventInit {
41
+ bubbles?: boolean;
42
+ cancelable?: boolean;
43
+ composed?: boolean;
44
+ }
45
+
46
+ interface EventListener {
47
+ (evt: Event): void;
48
+ }
49
+
50
+ interface EventListenerObject {
51
+ handleEvent(object: Event): void;
52
+ }
53
+
54
+ type _EventListenerOptions = typeof globalThis extends { onmessage: any } ? {} : EventListenerOptions;
55
+ interface EventListenerOptions {
56
+ capture?: boolean;
57
+ }
58
+
59
+ type _EventTarget = typeof globalThis extends { onmessage: any } ? {} : EventTarget;
60
+ interface EventTarget {
61
+ addEventListener(
62
+ type: string,
63
+ listener: EventListener | EventListenerObject,
64
+ options?: AddEventListenerOptions | boolean,
65
+ ): void;
66
+ dispatchEvent(event: Event): boolean;
67
+ removeEventListener(
68
+ type: string,
69
+ listener: EventListener | EventListenerObject,
70
+ options?: EventListenerOptions | boolean,
71
+ ): void;
72
+ }
73
+
74
+ declare global {
75
+ interface CustomEvent<T = any> extends _CustomEvent<T> {}
76
+ var CustomEvent: typeof globalThis extends { onmessage: any; CustomEvent: infer T } ? T
77
+ : {
78
+ prototype: CustomEvent;
79
+ new<T>(type: string, eventInitDict?: CustomEventInit<T>): CustomEvent<T>;
80
+ };
81
+
82
+ interface Event extends _Event {}
83
+ var Event: typeof globalThis extends { onmessage: any; Event: infer T } ? T
84
+ : {
85
+ prototype: Event;
86
+ new(type: string, eventInitDict?: EventInit): Event;
87
+ };
88
+
89
+ interface EventListenerOptions extends _EventListenerOptions {}
90
+
91
+ interface EventTarget extends _EventTarget {}
92
+ var EventTarget: typeof globalThis extends { onmessage: any; EventTarget: infer T } ? T
93
+ : {
94
+ prototype: EventTarget;
95
+ new(): EventTarget;
96
+ };
97
+ }
@@ -0,0 +1,46 @@
1
+ export {};
2
+
3
+ import * as undici from "undici-types";
4
+
5
+ type _EventSource = typeof globalThis extends { onmessage: any } ? {} : undici.EventSource;
6
+ type _FormData = typeof globalThis extends { onmessage: any } ? {} : undici.FormData;
7
+ type _Headers = typeof globalThis extends { onmessage: any } ? {} : undici.Headers;
8
+ type _MessageEvent = typeof globalThis extends { onmessage: any } ? {} : undici.MessageEvent;
9
+ type _Request = typeof globalThis extends { onmessage: any } ? {} : undici.Request;
10
+ type _RequestInit = typeof globalThis extends { onmessage: any } ? {} : undici.RequestInit;
11
+ type _Response = typeof globalThis extends { onmessage: any } ? {} : undici.Response;
12
+ type _ResponseInit = typeof globalThis extends { onmessage: any } ? {} : undici.ResponseInit;
13
+ type _WebSocket = typeof globalThis extends { onmessage: any } ? {} : undici.WebSocket;
14
+
15
+ declare global {
16
+ function fetch(
17
+ input: string | URL | Request,
18
+ init?: RequestInit,
19
+ ): Promise<Response>;
20
+
21
+ interface EventSource extends _EventSource {}
22
+ var EventSource: typeof globalThis extends { onmessage: any; EventSource: infer T } ? T : typeof undici.EventSource;
23
+
24
+ interface FormData extends _FormData {}
25
+ var FormData: typeof globalThis extends { onmessage: any; FormData: infer T } ? T : typeof undici.FormData;
26
+
27
+ interface Headers extends _Headers {}
28
+ var Headers: typeof globalThis extends { onmessage: any; Headers: infer T } ? T : typeof undici.Headers;
29
+
30
+ interface MessageEvent extends _MessageEvent {}
31
+ var MessageEvent: typeof globalThis extends { onmessage: any; MessageEvent: infer T } ? T
32
+ : typeof undici.MessageEvent;
33
+
34
+ interface Request extends _Request {}
35
+ var Request: typeof globalThis extends { onmessage: any; Request: infer T } ? T : typeof undici.Request;
36
+
37
+ interface RequestInit extends _RequestInit {}
38
+
39
+ interface Response extends _Response {}
40
+ var Response: typeof globalThis extends { onmessage: any; Response: infer T } ? T : typeof undici.Response;
41
+
42
+ interface ResponseInit extends _ResponseInit {}
43
+
44
+ interface WebSocket extends _WebSocket {}
45
+ var WebSocket: typeof globalThis extends { onmessage: any; WebSocket: infer T } ? T : typeof undici.WebSocket;
46
+ }
@@ -0,0 +1,22 @@
1
+ export {};
2
+
3
+ // lib.webworker has `WorkerNavigator` rather than `Navigator`, so conditionals use `onabort` instead of `onmessage`
4
+ type _Navigator = typeof globalThis extends { onabort: any } ? {} : Navigator;
5
+ interface Navigator {
6
+ readonly hardwareConcurrency: number;
7
+ readonly language: string;
8
+ readonly languages: readonly string[];
9
+ readonly platform: string;
10
+ readonly userAgent: string;
11
+ }
12
+
13
+ declare global {
14
+ interface Navigator extends _Navigator {}
15
+ var Navigator: typeof globalThis extends { onabort: any; Navigator: infer T } ? T : {
16
+ prototype: Navigator;
17
+ new(): Navigator;
18
+ };
19
+
20
+ // Needs conditional inference for lib.dom and lib.webworker compatibility
21
+ var navigator: typeof globalThis extends { onmessage: any; navigator: infer T } ? T : Navigator;
22
+ }
@@ -0,0 +1,24 @@
1
+ export {};
2
+
3
+ // These interfaces are absent from lib.webworker, so the conditionals use `onabort` rather than `onmessage`
4
+ type _Storage = typeof globalThis extends { onabort: any } ? {} : Storage;
5
+ interface Storage {
6
+ readonly length: number;
7
+ clear(): void;
8
+ getItem(key: string): string | null;
9
+ key(index: number): string | null;
10
+ removeItem(key: string): void;
11
+ setItem(key: string, value: string): void;
12
+ [key: string]: any;
13
+ }
14
+
15
+ declare global {
16
+ interface Storage extends _Storage {}
17
+ var Storage: typeof globalThis extends { onabort: any; Storage: infer T } ? T : {
18
+ prototype: Storage;
19
+ new(): Storage;
20
+ };
21
+
22
+ var localStorage: Storage;
23
+ var sessionStorage: Storage;
24
+ }
@@ -15,28 +15,31 @@
15
15
  *
16
16
  * ```js
17
17
  * import {
18
- * Worker, isMainThread, parentPort, workerData,
18
+ * Worker,
19
+ * isMainThread,
20
+ * parentPort,
21
+ * workerData,
19
22
  * } from 'node:worker_threads';
20
- * import { parse } from 'some-js-parsing-library';
21
23
  *
22
- * if (isMainThread) {
23
- * module.exports = function parseJSAsync(script) {
24
- * return new Promise((resolve, reject) => {
25
- * const worker = new Worker(__filename, {
26
- * workerData: script,
27
- * });
28
- * worker.on('message', resolve);
29
- * worker.on('error', reject);
30
- * worker.on('exit', (code) => {
31
- * if (code !== 0)
32
- * reject(new Error(`Worker stopped with exit code ${code}`));
33
- * });
34
- * });
35
- * };
36
- * } else {
24
+ * if (!isMainThread) {
25
+ * const { parse } = await import('some-js-parsing-library');
37
26
  * const script = workerData;
38
27
  * parentPort.postMessage(parse(script));
39
28
  * }
29
+ *
30
+ * export default function parseJSAsync(script) {
31
+ * return new Promise((resolve, reject) => {
32
+ * const worker = new Worker(new URL(import.meta.url), {
33
+ * workerData: script,
34
+ * });
35
+ * worker.on('message', resolve);
36
+ * worker.on('error', reject);
37
+ * worker.on('exit', (code) => {
38
+ * if (code !== 0)
39
+ * reject(new Error(`Worker stopped with exit code ${code}`));
40
+ * });
41
+ * });
42
+ * };
40
43
  * ```
41
44
  *
42
45
  * The above example spawns a Worker thread for each `parseJSAsync()` call. In
@@ -52,14 +55,15 @@
52
55
  * @see [source](https://github.com/nodejs/node/blob/v22.x/lib/worker_threads.js)
53
56
  */
54
57
  declare module "worker_threads" {
55
- import { Blob } from "node:buffer";
56
58
  import { Context } from "node:vm";
57
- import { EventEmitter } from "node:events";
59
+ import { EventEmitter, NodeEventTarget } from "node:events";
58
60
  import { EventLoopUtilityFunction } from "node:perf_hooks";
59
61
  import { FileHandle } from "node:fs/promises";
60
62
  import { Readable, Writable } from "node:stream";
63
+ import { ReadableStream, TransformStream, WritableStream } from "node:stream/web";
61
64
  import { URL } from "node:url";
62
- import { X509Certificate } from "node:crypto";
65
+ import { HeapInfo } from "node:v8";
66
+ import { MessageEvent } from "undici-types";
63
67
  const isInternalThread: boolean;
64
68
  const isMainThread: boolean;
65
69
  const parentPort: null | MessagePort;
@@ -89,7 +93,16 @@ declare module "worker_threads" {
89
93
  interface WorkerPerformance {
90
94
  eventLoopUtilization: EventLoopUtilityFunction;
91
95
  }
92
- type TransferListItem = ArrayBuffer | MessagePort | FileHandle | X509Certificate | Blob;
96
+ type Transferable =
97
+ | ArrayBuffer
98
+ | MessagePort
99
+ | AbortSignal
100
+ | FileHandle
101
+ | ReadableStream
102
+ | WritableStream
103
+ | TransformStream;
104
+ /** @deprecated Use `import { Transferable } from "node:worker_threads"` instead. */
105
+ type TransferListItem = Transferable;
93
106
  /**
94
107
  * Instances of the `worker.MessagePort` class represent one end of an
95
108
  * asynchronous, two-way communications channel. It can be used to transfer
@@ -98,7 +111,7 @@ declare module "worker_threads" {
98
111
  * This implementation matches [browser `MessagePort`](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort) s.
99
112
  * @since v10.5.0
100
113
  */
101
- class MessagePort extends EventEmitter {
114
+ class MessagePort implements EventTarget {
102
115
  /**
103
116
  * Disables further sending of messages on either side of the connection.
104
117
  * This method can be called when no further communication will happen over this `MessagePort`.
@@ -174,7 +187,12 @@ declare module "worker_threads" {
174
187
  * behind this API, see the `serialization API of the node:v8 module`.
175
188
  * @since v10.5.0
176
189
  */
177
- postMessage(value: any, transferList?: readonly TransferListItem[]): void;
190
+ postMessage(value: any, transferList?: readonly Transferable[]): void;
191
+ /**
192
+ * If true, the `MessagePort` object will keep the Node.js event loop active.
193
+ * @since v18.1.0, v16.17.0
194
+ */
195
+ hasRef(): boolean;
178
196
  /**
179
197
  * Opposite of `unref()`. Calling `ref()` on a previously `unref()`ed port does _not_ let the program exit if it's the only active handle left (the default
180
198
  * behavior). If the port is `ref()`ed, calling `ref()` again has no effect.
@@ -206,42 +224,32 @@ declare module "worker_threads" {
206
224
  * @since v10.5.0
207
225
  */
208
226
  start(): void;
209
- addListener(event: "close", listener: () => void): this;
227
+ addListener(event: "close", listener: (ev: Event) => void): this;
210
228
  addListener(event: "message", listener: (value: any) => void): this;
211
229
  addListener(event: "messageerror", listener: (error: Error) => void): this;
212
- addListener(event: string | symbol, listener: (...args: any[]) => void): this;
213
- emit(event: "close"): boolean;
230
+ addListener(event: string, listener: (arg: any) => void): this;
231
+ emit(event: "close", ev: Event): boolean;
214
232
  emit(event: "message", value: any): boolean;
215
233
  emit(event: "messageerror", error: Error): boolean;
216
- emit(event: string | symbol, ...args: any[]): boolean;
217
- on(event: "close", listener: () => void): this;
234
+ emit(event: string, arg: any): boolean;
235
+ off(event: "close", listener: (ev: Event) => void, options?: EventListenerOptions): this;
236
+ off(event: "message", listener: (value: any) => void, options?: EventListenerOptions): this;
237
+ off(event: "messageerror", listener: (error: Error) => void, options?: EventListenerOptions): this;
238
+ off(event: string, listener: (arg: any) => void, options?: EventListenerOptions): this;
239
+ on(event: "close", listener: (ev: Event) => void): this;
218
240
  on(event: "message", listener: (value: any) => void): this;
219
241
  on(event: "messageerror", listener: (error: Error) => void): this;
220
- on(event: string | symbol, listener: (...args: any[]) => void): this;
221
- once(event: "close", listener: () => void): this;
242
+ on(event: string, listener: (arg: any) => void): this;
243
+ once(event: "close", listener: (ev: Event) => void): this;
222
244
  once(event: "message", listener: (value: any) => void): this;
223
245
  once(event: "messageerror", listener: (error: Error) => void): this;
224
- once(event: string | symbol, listener: (...args: any[]) => void): this;
225
- prependListener(event: "close", listener: () => void): this;
226
- prependListener(event: "message", listener: (value: any) => void): this;
227
- prependListener(event: "messageerror", listener: (error: Error) => void): this;
228
- prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
229
- prependOnceListener(event: "close", listener: () => void): this;
230
- prependOnceListener(event: "message", listener: (value: any) => void): this;
231
- prependOnceListener(event: "messageerror", listener: (error: Error) => void): this;
232
- prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
233
- removeListener(event: "close", listener: () => void): this;
234
- removeListener(event: "message", listener: (value: any) => void): this;
235
- removeListener(event: "messageerror", listener: (error: Error) => void): this;
236
- removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
237
- off(event: "close", listener: () => void): this;
238
- off(event: "message", listener: (value: any) => void): this;
239
- off(event: "messageerror", listener: (error: Error) => void): this;
240
- off(event: string | symbol, listener: (...args: any[]) => void): this;
241
- addEventListener: EventTarget["addEventListener"];
242
- dispatchEvent: EventTarget["dispatchEvent"];
243
- removeEventListener: EventTarget["removeEventListener"];
246
+ once(event: string, listener: (arg: any) => void): this;
247
+ removeListener(event: "close", listener: (ev: Event) => void, options?: EventListenerOptions): this;
248
+ removeListener(event: "message", listener: (value: any) => void, options?: EventListenerOptions): this;
249
+ removeListener(event: "messageerror", listener: (error: Error) => void, options?: EventListenerOptions): this;
250
+ removeListener(event: string, listener: (arg: any) => void, options?: EventListenerOptions): this;
244
251
  }
252
+ interface MessagePort extends NodeEventTarget {}
245
253
  interface WorkerOptions {
246
254
  /**
247
255
  * List of arguments which would be stringified and appended to
@@ -261,7 +269,7 @@ declare module "worker_threads" {
261
269
  /**
262
270
  * Additional data to send in the first worker message.
263
271
  */
264
- transferList?: TransferListItem[] | undefined;
272
+ transferList?: Transferable[] | undefined;
265
273
  /**
266
274
  * @default true
267
275
  */
@@ -409,25 +417,7 @@ declare module "worker_threads" {
409
417
  * See `port.postMessage()` for more details.
410
418
  * @since v10.5.0
411
419
  */
412
- postMessage(value: any, transferList?: readonly TransferListItem[]): void;
413
- /**
414
- * Sends a value to another worker, identified by its thread ID.
415
- * @param threadId The target thread ID. If the thread ID is invalid, a `ERR_WORKER_MESSAGING_FAILED` error will be thrown.
416
- * If the target thread ID is the current thread ID, a `ERR_WORKER_MESSAGING_SAME_THREAD` error will be thrown.
417
- * @param value The value to send.
418
- * @param transferList If one or more `MessagePort`-like objects are passed in value, a `transferList` is required for those items
419
- * or `ERR_MISSING_MESSAGE_PORT_IN_TRANSFER_LIST` is thrown. See `port.postMessage()` for more information.
420
- * @param timeout Time to wait for the message to be delivered in milliseconds. By default it's `undefined`, which means wait forever.
421
- * If the operation times out, a `ERR_WORKER_MESSAGING_TIMEOUT` error is thrown.
422
- * @since v22.5.0
423
- */
424
- postMessageToThread(threadId: number, value: any, timeout?: number): Promise<void>;
425
- postMessageToThread(
426
- threadId: number,
427
- value: any,
428
- transferList: readonly TransferListItem[],
429
- timeout?: number,
430
- ): Promise<void>;
420
+ postMessage(value: any, transferList?: readonly Transferable[]): void;
431
421
  /**
432
422
  * Opposite of `unref()`, calling `ref()` on a previously `unref()`ed worker does _not_ let the program exit if it's the only active handle left (the default
433
423
  * behavior). If the worker is `ref()`ed, calling `ref()` again has
@@ -447,6 +437,13 @@ declare module "worker_threads" {
447
437
  * @since v10.5.0
448
438
  */
449
439
  terminate(): Promise<number>;
440
+ /**
441
+ * This method returns a `Promise` that will resolve to an object identical to `process.threadCpuUsage()`,
442
+ * or reject with an `ERR_WORKER_NOT_RUNNING` error if the worker is no longer running.
443
+ * This methods allows the statistics to be observed from outside the actual thread.
444
+ * @since v22.19.0
445
+ */
446
+ cpuUsage(prev?: NodeJS.CpuUsage): Promise<NodeJS.CpuUsage>;
450
447
  /**
451
448
  * Returns a readable stream for a V8 snapshot of the current state of the Worker.
452
449
  * See `v8.getHeapSnapshot()` for more details.
@@ -457,6 +454,25 @@ declare module "worker_threads" {
457
454
  * @return A promise for a Readable Stream containing a V8 heap snapshot
458
455
  */
459
456
  getHeapSnapshot(): Promise<Readable>;
457
+ /**
458
+ * This method returns a `Promise` that will resolve to an object identical to `v8.getHeapStatistics()`,
459
+ * or reject with an `ERR_WORKER_NOT_RUNNING` error if the worker is no longer running.
460
+ * This methods allows the statistics to be observed from outside the actual thread.
461
+ * @since v22.16.0
462
+ */
463
+ getHeapStatistics(): Promise<HeapInfo>;
464
+ /**
465
+ * Calls `worker.terminate()` when the dispose scope is exited.
466
+ *
467
+ * ```js
468
+ * async function example() {
469
+ * await using worker = new Worker('for (;;) {}', { eval: true });
470
+ * // Worker is automatically terminate when the scope is exited.
471
+ * }
472
+ * ```
473
+ * @since v22.18.0
474
+ */
475
+ [Symbol.asyncDispose](): Promise<void>;
460
476
  addListener(event: "error", listener: (err: Error) => void): this;
461
477
  addListener(event: "exit", listener: (exitCode: number) => void): this;
462
478
  addListener(event: "message", listener: (value: any) => void): this;
@@ -537,18 +553,18 @@ declare module "worker_threads" {
537
553
  * ```
538
554
  * @since v15.4.0
539
555
  */
540
- class BroadcastChannel {
556
+ class BroadcastChannel extends EventTarget {
541
557
  readonly name: string;
542
558
  /**
543
559
  * Invoked with a single \`MessageEvent\` argument when a message is received.
544
560
  * @since v15.4.0
545
561
  */
546
- onmessage: (message: unknown) => void;
562
+ onmessage: (message: MessageEvent) => void;
547
563
  /**
548
564
  * Invoked with a received message cannot be deserialized.
549
565
  * @since v15.4.0
550
566
  */
551
- onmessageerror: (message: unknown) => void;
567
+ onmessageerror: (message: MessageEvent) => void;
552
568
  constructor(name: string);
553
569
  /**
554
570
  * Closes the `BroadcastChannel` connection.
@@ -701,7 +717,25 @@ declare module "worker_threads" {
701
717
  * @param value Any arbitrary, cloneable JavaScript value that will be cloned and passed automatically to all new `Worker` instances. If `value` is passed as `undefined`, any previously set value
702
718
  * for the `key` will be deleted.
703
719
  */
704
- function setEnvironmentData(key: Serializable, value: Serializable): void;
720
+ function setEnvironmentData(key: Serializable, value?: Serializable): void;
721
+ /**
722
+ * Sends a value to another worker, identified by its thread ID.
723
+ * @param threadId The target thread ID. If the thread ID is invalid, a `ERR_WORKER_MESSAGING_FAILED` error will be thrown.
724
+ * If the target thread ID is the current thread ID, a `ERR_WORKER_MESSAGING_SAME_THREAD` error will be thrown.
725
+ * @param value The value to send.
726
+ * @param transferList If one or more `MessagePort`-like objects are passed in value, a `transferList` is required for those items
727
+ * or `ERR_MISSING_MESSAGE_PORT_IN_TRANSFER_LIST` is thrown. See `port.postMessage()` for more information.
728
+ * @param timeout Time to wait for the message to be delivered in milliseconds. By default it's `undefined`, which means wait forever.
729
+ * If the operation times out, a `ERR_WORKER_MESSAGING_TIMEOUT` error is thrown.
730
+ * @since v22.5.0
731
+ */
732
+ function postMessageToThread(threadId: number, value: any, timeout?: number): Promise<void>;
733
+ function postMessageToThread(
734
+ threadId: number,
735
+ value: any,
736
+ transferList: readonly Transferable[],
737
+ timeout?: number,
738
+ ): Promise<void>;
705
739
 
706
740
  import {
707
741
  BroadcastChannel as _BroadcastChannel,
@@ -709,6 +743,10 @@ declare module "worker_threads" {
709
743
  MessagePort as _MessagePort,
710
744
  } from "worker_threads";
711
745
  global {
746
+ function structuredClone<T>(
747
+ value: T,
748
+ options?: { transfer?: Transferable[] },
749
+ ): T;
712
750
  /**
713
751
  * `BroadcastChannel` class is a global reference for `import { BroadcastChannel } from 'worker_threads'`
714
752
  * https://nodejs.org/api/globals.html#broadcastchannel