@types/node 20.17.28 → 20.17.30

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.17/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: Thu, 27 Mar 2025 03:13:14 GMT
11
+ * Last updated: Tue, 01 Apr 2025 16:38:24 GMT
12
12
  * Dependencies: [undici-types](https://npmjs.com/package/undici-types)
13
13
 
14
14
  # Credits
node v20.17/fs.d.ts CHANGED
@@ -579,7 +579,7 @@ declare module "fs" {
579
579
  * @since v0.8.6
580
580
  * @param [len=0]
581
581
  */
582
- export function truncate(path: PathLike, len: number | undefined | null, callback: NoParamCallback): void;
582
+ export function truncate(path: PathLike, len: number | undefined, callback: NoParamCallback): void;
583
583
  /**
584
584
  * Asynchronous truncate(2) - Truncate a file to a specified length.
585
585
  * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
@@ -591,7 +591,7 @@ declare module "fs" {
591
591
  * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
592
592
  * @param len If not specified, defaults to `0`.
593
593
  */
594
- function __promisify__(path: PathLike, len?: number | null): Promise<void>;
594
+ function __promisify__(path: PathLike, len?: number): Promise<void>;
595
595
  }
596
596
  /**
597
597
  * Truncates the file. Returns `undefined`. A file descriptor can also be
@@ -602,7 +602,7 @@ declare module "fs" {
602
602
  * @since v0.8.6
603
603
  * @param [len=0]
604
604
  */
605
- export function truncateSync(path: PathLike, len?: number | null): void;
605
+ export function truncateSync(path: PathLike, len?: number): void;
606
606
  /**
607
607
  * Truncates the file descriptor. No arguments other than a possible exception are
608
608
  * given to the completion callback.
@@ -646,7 +646,7 @@ declare module "fs" {
646
646
  * @since v0.8.6
647
647
  * @param [len=0]
648
648
  */
649
- export function ftruncate(fd: number, len: number | undefined | null, callback: NoParamCallback): void;
649
+ export function ftruncate(fd: number, len: number | undefined, callback: NoParamCallback): void;
650
650
  /**
651
651
  * Asynchronous ftruncate(2) - Truncate a file to a specified length.
652
652
  * @param fd A file descriptor.
@@ -658,7 +658,7 @@ declare module "fs" {
658
658
  * @param fd A file descriptor.
659
659
  * @param len If not specified, defaults to `0`.
660
660
  */
661
- function __promisify__(fd: number, len?: number | null): Promise<void>;
661
+ function __promisify__(fd: number, len?: number): Promise<void>;
662
662
  }
663
663
  /**
664
664
  * Truncates the file descriptor. Returns `undefined`.
@@ -668,7 +668,7 @@ declare module "fs" {
668
668
  * @since v0.8.6
669
669
  * @param [len=0]
670
670
  */
671
- export function ftruncateSync(fd: number, len?: number | null): void;
671
+ export function ftruncateSync(fd: number, len?: number): void;
672
672
  /**
673
673
  * Asynchronously changes owner and group of a file. No arguments other than a
674
674
  * possible exception are given to the completion callback.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@types/node",
3
- "version": "20.17.28",
3
+ "version": "20.17.30",
4
4
  "description": "TypeScript definitions for node",
5
5
  "homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node",
6
6
  "license": "MIT",
@@ -215,6 +215,6 @@
215
215
  "undici-types": "~6.19.2"
216
216
  },
217
217
  "peerDependencies": {},
218
- "typesPublisherContentHash": "0e6e31fc35f69eb67f9b49e14e070a90616484c787f902edc4ef687f2777f872",
219
- "typeScriptVersion": "5.0"
218
+ "typesPublisherContentHash": "0475512c9c56bcf062679dadeea2661f3bd08ba32001740b64dd1c586a144796",
219
+ "typeScriptVersion": "5.1"
220
220
  }
@@ -1,15 +1,17 @@
1
1
  /**
2
2
  * The `timers/promises` API provides an alternative set of timer functions
3
- * that return `Promise` objects. The API is accessible via `import timersPromises from 'node:timers/promises'`.
3
+ * that return `Promise` objects. The API is accessible via
4
+ * `require('node:timers/promises')`.
4
5
  *
5
6
  * ```js
6
7
  * import {
7
8
  * setTimeout,
8
9
  * setImmediate,
9
10
  * setInterval,
10
- * } from 'timers/promises';
11
+ * } from 'node:timers/promises';
11
12
  * ```
12
13
  * @since v15.0.0
14
+ * @see [source](https://github.com/nodejs/node/blob/v20.x/lib/timers/promises.js)
13
15
  */
14
16
  declare module "timers/promises" {
15
17
  import { TimerOptions } from "node:timers";
@@ -17,14 +19,15 @@ declare module "timers/promises" {
17
19
  * ```js
18
20
  * import {
19
21
  * setTimeout,
20
- * } from 'timers/promises';
22
+ * } from 'node:timers/promises';
21
23
  *
22
24
  * const res = await setTimeout(100, 'result');
23
25
  *
24
26
  * console.log(res); // Prints 'result'
25
27
  * ```
26
28
  * @since v15.0.0
27
- * @param [delay=1] The number of milliseconds to wait before fulfilling the promise.
29
+ * @param delay The number of milliseconds to wait before fulfilling the
30
+ * promise. **Default:** `1`.
28
31
  * @param value A value with which the promise is fulfilled.
29
32
  */
30
33
  function setTimeout<T = void>(delay?: number, value?: T, options?: TimerOptions): Promise<T>;
@@ -32,7 +35,7 @@ declare module "timers/promises" {
32
35
  * ```js
33
36
  * import {
34
37
  * setImmediate,
35
- * } from 'timers/promises';
38
+ * } from 'node:timers/promises';
36
39
  *
37
40
  * const res = await setImmediate('result');
38
41
  *
@@ -50,7 +53,7 @@ declare module "timers/promises" {
50
53
  * ```js
51
54
  * import {
52
55
  * setInterval,
53
- * } from 'timers/promises';
56
+ * } from 'node:timers/promises';
54
57
  *
55
58
  * const interval = 100;
56
59
  * for await (const startTime of setInterval(interval, Date.now())) {
@@ -62,33 +65,41 @@ declare module "timers/promises" {
62
65
  * console.log(Date.now());
63
66
  * ```
64
67
  * @since v15.9.0
68
+ * @param delay The number of milliseconds to wait between iterations.
69
+ * **Default:** `1`.
70
+ * @param value A value with which the iterator returns.
65
71
  */
66
- function setInterval<T = void>(delay?: number, value?: T, options?: TimerOptions): AsyncIterable<T>;
72
+ function setInterval<T = void>(delay?: number, value?: T, options?: TimerOptions): NodeJS.AsyncIterator<T>;
67
73
  interface Scheduler {
68
74
  /**
69
- * An experimental API defined by the [Scheduling APIs](https://github.com/WICG/scheduling-apis) draft specification being developed as a standard Web Platform API.
75
+ * An experimental API defined by the [Scheduling APIs](https://github.com/WICG/scheduling-apis) draft specification
76
+ * being developed as a standard Web Platform API.
70
77
  *
71
- * Calling `timersPromises.scheduler.wait(delay, options)` is roughly equivalent to calling `timersPromises.setTimeout(delay, undefined, options)` except that the `ref`
72
- * option is not supported.
78
+ * Calling `timersPromises.scheduler.wait(delay, options)` is roughly equivalent
79
+ * to calling `timersPromises.setTimeout(delay, undefined, options)` except that
80
+ * the `ref` option is not supported.
73
81
  *
74
82
  * ```js
75
83
  * import { scheduler } from 'node:timers/promises';
76
84
  *
77
85
  * await scheduler.wait(1000); // Wait one second before continuing
78
86
  * ```
79
- * @since v16.14.0
87
+ * @since v17.3.0, v16.14.0
80
88
  * @experimental
81
- * @param [delay=1] The number of milliseconds to wait before fulfilling the promise.
89
+ * @param delay The number of milliseconds to wait before resolving the
90
+ * promise.
82
91
  */
83
- wait: (delay?: number, options?: Pick<TimerOptions, "signal">) => Promise<void>;
92
+ wait(delay: number, options?: { signal?: AbortSignal }): Promise<void>;
84
93
  /**
85
- * An experimental API defined by the [Scheduling APIs](https://nodejs.org/docs/latest-v20.x/api/async_hooks.html#promise-execution-tracking) draft specification
94
+ * An experimental API defined by the [Scheduling APIs](https://github.com/WICG/scheduling-apis) draft specification
86
95
  * being developed as a standard Web Platform API.
87
- * Calling `timersPromises.scheduler.yield()` is equivalent to calling `timersPromises.setImmediate()` with no arguments.
88
- * @since v16.14.0
96
+ *
97
+ * Calling `timersPromises.scheduler.yield()` is equivalent to calling
98
+ * `timersPromises.setImmediate()` with no arguments.
99
+ * @since v17.3.0, v16.14.0
89
100
  * @experimental
90
101
  */
91
- yield: () => Promise<void>;
102
+ yield(): Promise<void>;
92
103
  }
93
104
  const scheduler: Scheduler;
94
105
  }
node v20.17/timers.d.ts CHANGED
@@ -6,16 +6,12 @@
6
6
  * The timer functions within Node.js implement a similar API as the timers API
7
7
  * provided by Web Browsers but use a different internal implementation that is
8
8
  * built around the Node.js [Event Loop](https://nodejs.org/en/docs/guides/event-loop-timers-and-nexttick/#setimmediate-vs-settimeout).
9
- * @see [source](https://github.com/nodejs/node/blob/v20.13.1/lib/timers.js)
9
+ * @see [source](https://github.com/nodejs/node/blob/v20.x/lib/timers.js)
10
10
  */
11
11
  declare module "timers" {
12
12
  import { Abortable } from "node:events";
13
- import {
14
- setImmediate as setImmediatePromise,
15
- setInterval as setIntervalPromise,
16
- setTimeout as setTimeoutPromise,
17
- } from "node:timers/promises";
18
- interface TimerOptions extends Abortable {
13
+ import * as promises from "node:timers/promises";
14
+ export interface TimerOptions extends Abortable {
19
15
  /**
20
16
  * Set to `false` to indicate that the scheduled `Timeout`
21
17
  * should not require the Node.js event loop to remain active.
@@ -23,38 +19,33 @@ declare module "timers" {
23
19
  */
24
20
  ref?: boolean | undefined;
25
21
  }
26
- let setTimeout: typeof global.setTimeout;
27
- let clearTimeout: typeof global.clearTimeout;
28
- let setInterval: typeof global.setInterval;
29
- let clearInterval: typeof global.clearInterval;
30
- let setImmediate: typeof global.setImmediate;
31
- let clearImmediate: typeof global.clearImmediate;
32
22
  global {
33
23
  namespace NodeJS {
34
- // compatibility with older typings
35
- interface Timer extends RefCounted {
36
- hasRef(): boolean;
37
- refresh(): this;
38
- [Symbol.toPrimitive](): number;
39
- }
40
24
  /**
41
25
  * This object is created internally and is returned from `setImmediate()`. It
42
26
  * can be passed to `clearImmediate()` in order to cancel the scheduled
43
27
  * actions.
44
28
  *
45
29
  * By default, when an immediate is scheduled, the Node.js event loop will continue
46
- * running as long as the immediate is active. The `Immediate` object returned by `setImmediate()` exports both `immediate.ref()` and `immediate.unref()` functions that can be used to
47
- * control this default behavior.
30
+ * running as long as the immediate is active. The `Immediate` object returned by
31
+ * `setImmediate()` exports both `immediate.ref()` and `immediate.unref()`
32
+ * functions that can be used to control this default behavior.
48
33
  */
49
- class Immediate implements RefCounted {
34
+ interface Immediate extends RefCounted, Disposable {
50
35
  /**
51
- * When called, requests that the Node.js event loop _not_ exit so long as the `Immediate` is active. Calling `immediate.ref()` multiple times will have no
36
+ * If true, the `Immediate` object will keep the Node.js event loop active.
37
+ * @since v11.0.0
38
+ */
39
+ hasRef(): boolean;
40
+ /**
41
+ * When called, requests that the Node.js event loop _not_ exit so long as the
42
+ * `Immediate` is active. Calling `immediate.ref()` multiple times will have no
52
43
  * effect.
53
44
  *
54
45
  * By default, all `Immediate` objects are "ref'ed", making it normally unnecessary
55
46
  * to call `immediate.ref()` unless `immediate.unref()` had been called previously.
56
47
  * @since v9.7.0
57
- * @return a reference to `immediate`
48
+ * @returns a reference to `immediate`
58
49
  */
59
50
  ref(): this;
60
51
  /**
@@ -63,53 +54,58 @@ declare module "timers" {
63
54
  * running, the process may exit before the `Immediate` object's callback is
64
55
  * invoked. Calling `immediate.unref()` multiple times will have no effect.
65
56
  * @since v9.7.0
66
- * @return a reference to `immediate`
57
+ * @returns a reference to `immediate`
67
58
  */
68
59
  unref(): this;
69
- /**
70
- * If true, the `Immediate` object will keep the Node.js event loop active.
71
- * @since v11.0.0
72
- */
73
- hasRef(): boolean;
74
- _onImmediate: Function; // to distinguish it from the Timeout class
75
60
  /**
76
61
  * Cancels the immediate. This is similar to calling `clearImmediate()`.
77
- * @since v20.5.0
62
+ * @since v20.5.0, v18.18.0
63
+ * @experimental
78
64
  */
79
65
  [Symbol.dispose](): void;
66
+ _onImmediate(...args: any[]): void;
67
+ }
68
+ // Legacy interface used in Node.js v9 and prior
69
+ /** @deprecated Use `NodeJS.Timeout` instead. */
70
+ interface Timer extends RefCounted {
71
+ hasRef(): boolean;
72
+ refresh(): this;
73
+ [Symbol.toPrimitive](): number;
80
74
  }
81
75
  /**
82
- * 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
83
- * scheduled actions.
76
+ * This object is created internally and is returned from `setTimeout()` and
77
+ * `setInterval()`. It can be passed to either `clearTimeout()` or
78
+ * `clearInterval()` in order to cancel the scheduled actions.
84
79
  *
85
- * By default, when a timer is scheduled using either `setTimeout()` or `setInterval()`, the Node.js event loop will continue running as long as the
80
+ * By default, when a timer is scheduled using either `setTimeout()` or
81
+ * `setInterval()`, the Node.js event loop will continue running as long as the
86
82
  * timer is active. Each of the `Timeout` objects returned by these functions
87
83
  * export both `timeout.ref()` and `timeout.unref()` functions that can be used to
88
84
  * control this default behavior.
89
85
  */
90
- class Timeout implements Timer {
91
- /**
92
- * When called, requests that the Node.js event loop _not_ exit so long as the`Timeout` is active. Calling `timeout.ref()` multiple times will have no effect.
93
- *
94
- * By default, all `Timeout` objects are "ref'ed", making it normally unnecessary
95
- * to call `timeout.ref()` unless `timeout.unref()` had been called previously.
96
- * @since v0.9.1
97
- * @return a reference to `timeout`
98
- */
99
- ref(): this;
86
+ interface Timeout extends RefCounted, Disposable, Timer {
100
87
  /**
101
- * When called, the active `Timeout` object will not require the Node.js event loop
102
- * to remain active. If there is no other activity keeping the event loop running,
103
- * the process may exit before the `Timeout` object's callback is invoked. Calling `timeout.unref()` multiple times will have no effect.
88
+ * Cancels the timeout.
104
89
  * @since v0.9.1
105
- * @return a reference to `timeout`
90
+ * @legacy Use `clearTimeout()` instead.
91
+ * @returns a reference to `timeout`
106
92
  */
107
- unref(): this;
93
+ close(): this;
108
94
  /**
109
95
  * If true, the `Timeout` object will keep the Node.js event loop active.
110
96
  * @since v11.0.0
111
97
  */
112
98
  hasRef(): boolean;
99
+ /**
100
+ * When called, requests that the Node.js event loop _not_ exit so long as the
101
+ * `Timeout` is active. Calling `timeout.ref()` multiple times will have no effect.
102
+ *
103
+ * By default, all `Timeout` objects are "ref'ed", making it normally unnecessary
104
+ * to call `timeout.ref()` unless `timeout.unref()` had been called previously.
105
+ * @since v0.9.1
106
+ * @returns a reference to `timeout`
107
+ */
108
+ ref(): this;
113
109
  /**
114
110
  * Sets the timer's start time to the current time, and reschedules the timer to
115
111
  * call its callback at the previously specified duration adjusted to the current
@@ -119,53 +115,69 @@ declare module "timers" {
119
115
  * Using this on a timer that has already called its callback will reactivate the
120
116
  * timer.
121
117
  * @since v10.2.0
122
- * @return a reference to `timeout`
118
+ * @returns a reference to `timeout`
123
119
  */
124
120
  refresh(): this;
121
+ /**
122
+ * When called, the active `Timeout` object will not require the Node.js event loop
123
+ * to remain active. If there is no other activity keeping the event loop running,
124
+ * the process may exit before the `Timeout` object's callback is invoked. Calling
125
+ * `timeout.unref()` multiple times will have no effect.
126
+ * @since v0.9.1
127
+ * @returns a reference to `timeout`
128
+ */
129
+ unref(): this;
130
+ /**
131
+ * Coerce a `Timeout` to a primitive. The primitive can be used to
132
+ * clear the `Timeout`. The primitive can only be used in the
133
+ * same thread where the timeout was created. Therefore, to use it
134
+ * across `worker_threads` it must first be passed to the correct
135
+ * thread. This allows enhanced compatibility with browser
136
+ * `setTimeout()` and `setInterval()` implementations.
137
+ * @since v14.9.0, v12.19.0
138
+ */
125
139
  [Symbol.toPrimitive](): number;
126
140
  /**
127
141
  * Cancels the timeout.
128
- * @since v20.5.0
142
+ * @since v20.5.0, v18.18.0
143
+ * @experimental
129
144
  */
130
145
  [Symbol.dispose](): void;
146
+ _onTimeout(...args: any[]): void;
131
147
  }
132
148
  }
133
149
  /**
134
- * Schedules execution of a one-time `callback` after `delay` milliseconds.
135
- *
136
- * The `callback` will likely not be invoked in precisely `delay` milliseconds.
137
- * Node.js makes no guarantees about the exact timing of when callbacks will fire,
138
- * nor of their ordering. The callback will be called as close as possible to the
139
- * time specified.
150
+ * Schedules the "immediate" execution of the `callback` after I/O events'
151
+ * callbacks.
140
152
  *
141
- * When `delay` is larger than `2147483647` or less than `1`, the `delay` will be set to `1`. Non-integer delays are truncated to an integer.
153
+ * When multiple calls to `setImmediate()` are made, the `callback` functions are
154
+ * queued for execution in the order in which they are created. The entire callback
155
+ * queue is processed every event loop iteration. If an immediate timer is queued
156
+ * from inside an executing callback, that timer will not be triggered until the
157
+ * next event loop iteration.
142
158
  *
143
159
  * If `callback` is not a function, a `TypeError` will be thrown.
144
160
  *
145
- * This method has a custom variant for promises that is available using `timersPromises.setTimeout()`.
146
- * @since v0.0.1
147
- * @param callback The function to call when the timer elapses.
148
- * @param [delay=1] The number of milliseconds to wait before calling the `callback`.
161
+ * This method has a custom variant for promises that is available using
162
+ * `timersPromises.setImmediate()`.
163
+ * @since v0.9.1
164
+ * @param callback The function to call at the end of this turn of
165
+ * the Node.js [Event Loop](https://nodejs.org/en/docs/guides/event-loop-timers-and-nexttick/#setimmediate-vs-settimeout)
149
166
  * @param args Optional arguments to pass when the `callback` is called.
150
- * @return for use with {@link clearTimeout}
167
+ * @returns for use with `clearImmediate()`
151
168
  */
152
- function setTimeout<TArgs extends any[]>(
169
+ function setImmediate<TArgs extends any[]>(
153
170
  callback: (...args: TArgs) => void,
154
- delay?: number,
155
171
  ...args: TArgs
156
- ): NodeJS.Timeout;
157
- // util.promisify no rest args compability
172
+ ): NodeJS.Immediate;
173
+ // Allow a single void-accepting argument to be optional in arguments lists.
174
+ // Allows usage such as `new Promise(resolve => setTimeout(resolve, ms))` (#54258)
158
175
  // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
159
- function setTimeout(callback: (args: void) => void, delay?: number): NodeJS.Timeout;
160
- namespace setTimeout {
161
- const __promisify__: typeof setTimeoutPromise;
176
+ function setImmediate(callback: (_: void) => void): NodeJS.Immediate;
177
+ namespace setImmediate {
178
+ import __promisify__ = promises.setImmediate;
179
+ export { __promisify__ };
162
180
  }
163
- /**
164
- * Cancels a `Timeout` object created by `setTimeout()`.
165
- * @since v0.0.1
166
- * @param timeout A `Timeout` object as returned by {@link setTimeout} or the `primitive` of the `Timeout` object as a string or a number.
167
- */
168
- function clearTimeout(timeoutId: NodeJS.Timeout | string | number | undefined): void;
169
181
  /**
170
182
  * Schedules repeated execution of `callback` every `delay` milliseconds.
171
183
  *
@@ -174,66 +186,100 @@ declare module "timers" {
174
186
  *
175
187
  * If `callback` is not a function, a `TypeError` will be thrown.
176
188
  *
177
- * This method has a custom variant for promises that is available using `timersPromises.setInterval()`.
189
+ * This method has a custom variant for promises that is available using
190
+ * `timersPromises.setInterval()`.
178
191
  * @since v0.0.1
179
192
  * @param callback The function to call when the timer elapses.
180
- * @param [delay=1] The number of milliseconds to wait before calling the `callback`.
193
+ * @param delay The number of milliseconds to wait before calling the
194
+ * `callback`. **Default:** `1`.
181
195
  * @param args Optional arguments to pass when the `callback` is called.
182
- * @return for use with {@link clearInterval}
196
+ * @returns for use with `clearInterval()`
183
197
  */
184
198
  function setInterval<TArgs extends any[]>(
185
199
  callback: (...args: TArgs) => void,
186
200
  delay?: number,
187
201
  ...args: TArgs
188
202
  ): NodeJS.Timeout;
189
- // util.promisify no rest args compability
203
+ // Allow a single void-accepting argument to be optional in arguments lists.
204
+ // Allows usage such as `new Promise(resolve => setTimeout(resolve, ms))` (#54258)
190
205
  // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
191
- function setInterval(callback: (args: void) => void, delay?: number): NodeJS.Timeout;
192
- namespace setInterval {
193
- const __promisify__: typeof setIntervalPromise;
194
- }
195
- /**
196
- * Cancels a `Timeout` object created by `setInterval()`.
197
- * @since v0.0.1
198
- * @param timeout A `Timeout` object as returned by {@link setInterval} or the `primitive` of the `Timeout` object as a string or a number.
199
- */
200
- function clearInterval(intervalId: NodeJS.Timeout | string | number | undefined): void;
206
+ function setInterval(callback: (_: void) => void, delay?: number): NodeJS.Timeout;
201
207
  /**
202
- * Schedules the "immediate" execution of the `callback` after I/O events'
203
- * callbacks.
208
+ * Schedules execution of a one-time `callback` after `delay` milliseconds.
204
209
  *
205
- * When multiple calls to `setImmediate()` are made, the `callback` functions are
206
- * queued for execution in the order in which they are created. The entire callback
207
- * queue is processed every event loop iteration. If an immediate timer is queued
208
- * from inside an executing callback, that timer will not be triggered until the
209
- * next event loop iteration.
210
+ * The `callback` will likely not be invoked in precisely `delay` milliseconds.
211
+ * Node.js makes no guarantees about the exact timing of when callbacks will fire,
212
+ * nor of their ordering. The callback will be called as close as possible to the
213
+ * time specified.
214
+ *
215
+ * When `delay` is larger than `2147483647` or less than `1` or `NaN`, the `delay`
216
+ * will be set to `1`. Non-integer delays are truncated to an integer.
210
217
  *
211
218
  * If `callback` is not a function, a `TypeError` will be thrown.
212
219
  *
213
- * This method has a custom variant for promises that is available using `timersPromises.setImmediate()`.
214
- * @since v0.9.1
215
- * @param callback The function to call at the end of this turn of the Node.js `Event Loop`
220
+ * This method has a custom variant for promises that is available using
221
+ * `timersPromises.setTimeout()`.
222
+ * @since v0.0.1
223
+ * @param callback The function to call when the timer elapses.
224
+ * @param delay The number of milliseconds to wait before calling the
225
+ * `callback`. **Default:** `1`.
216
226
  * @param args Optional arguments to pass when the `callback` is called.
217
- * @return for use with {@link clearImmediate}
227
+ * @returns for use with `clearTimeout()`
218
228
  */
219
- function setImmediate<TArgs extends any[]>(
229
+ function setTimeout<TArgs extends any[]>(
220
230
  callback: (...args: TArgs) => void,
231
+ delay?: number,
221
232
  ...args: TArgs
222
- ): NodeJS.Immediate;
223
- // util.promisify no rest args compability
233
+ ): NodeJS.Timeout;
234
+ // Allow a single void-accepting argument to be optional in arguments lists.
235
+ // Allows usage such as `new Promise(resolve => setTimeout(resolve, ms))` (#54258)
224
236
  // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
225
- function setImmediate(callback: (args: void) => void): NodeJS.Immediate;
226
- namespace setImmediate {
227
- const __promisify__: typeof setImmediatePromise;
237
+ function setTimeout(callback: (_: void) => void, delay?: number): NodeJS.Timeout;
238
+ namespace setTimeout {
239
+ import __promisify__ = promises.setTimeout;
240
+ export { __promisify__ };
228
241
  }
229
242
  /**
230
243
  * Cancels an `Immediate` object created by `setImmediate()`.
231
244
  * @since v0.9.1
232
- * @param immediate An `Immediate` object as returned by {@link setImmediate}.
245
+ * @param immediate An `Immediate` object as returned by `setImmediate()`.
246
+ */
247
+ function clearImmediate(immediate: NodeJS.Immediate | undefined): void;
248
+ /**
249
+ * Cancels a `Timeout` object created by `setInterval()`.
250
+ * @since v0.0.1
251
+ * @param timeout A `Timeout` object as returned by `setInterval()`
252
+ * or the primitive of the `Timeout` object as a string or a number.
253
+ */
254
+ function clearInterval(timeout: NodeJS.Timeout | string | number | undefined): void;
255
+ /**
256
+ * Cancels a `Timeout` object created by `setTimeout()`.
257
+ * @since v0.0.1
258
+ * @param timeout A `Timeout` object as returned by `setTimeout()`
259
+ * or the primitive of the `Timeout` object as a string or a number.
260
+ */
261
+ function clearTimeout(timeout: NodeJS.Timeout | string | number | undefined): void;
262
+ /**
263
+ * The `queueMicrotask()` method queues a microtask to invoke `callback`. If
264
+ * `callback` throws an exception, the `process` object `'uncaughtException'`
265
+ * event will be emitted.
266
+ *
267
+ * The microtask queue is managed by V8 and may be used in a similar manner to
268
+ * the `process.nextTick()` queue, which is managed by Node.js. The
269
+ * `process.nextTick()` queue is always processed before the microtask queue
270
+ * within each turn of the Node.js event loop.
271
+ * @since v11.0.0
272
+ * @param callback Function to be queued.
233
273
  */
234
- function clearImmediate(immediateId: NodeJS.Immediate | undefined): void;
235
274
  function queueMicrotask(callback: () => void): void;
236
275
  }
276
+ import clearImmediate = globalThis.clearImmediate;
277
+ import clearInterval = globalThis.clearInterval;
278
+ import clearTimeout = globalThis.clearTimeout;
279
+ import setImmediate = globalThis.setImmediate;
280
+ import setInterval = globalThis.setInterval;
281
+ import setTimeout = globalThis.setTimeout;
282
+ export { clearImmediate, clearInterval, clearTimeout, promises, setImmediate, setInterval, setTimeout };
237
283
  }
238
284
  declare module "node:timers" {
239
285
  export * from "timers";