Skip to content

Commit 2ec4a53

Browse files
authored
🤖 Merge PR DefinitelyTyped#72938 [node] Update typings to v20.19.0 by @sapphi-red
1 parent fdceb43 commit 2ec4a53

File tree

18 files changed

+602
-67
lines changed

18 files changed

+602
-67
lines changed

types/node/v20/globals.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type _RequestInit = typeof globalThis extends { onmessage: any } ? {}
1212
: import("undici-types").RequestInit;
1313
type _ResponseInit = typeof globalThis extends { onmessage: any } ? {}
1414
: import("undici-types").ResponseInit;
15+
type _EventSource = typeof globalThis extends { onmessage: any } ? {} : import("undici-types").EventSource;
1516
// #endregion Fetch and friends
1617

1718
// #region DOMException
@@ -327,5 +328,8 @@ declare global {
327328
} ? T
328329
: typeof import("undici-types").MessageEvent;
329330

331+
interface EventSource extends _EventSource {}
332+
var EventSource: typeof globalThis extends { onmessage: any; EventSource: infer T } ? T
333+
: typeof import("undici-types").EventSource;
330334
// #endregion fetch
331335
}

types/node/v20/inspector.d.ts

Lines changed: 272 additions & 2 deletions
Large diffs are not rendered by default.

types/node/v20/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "@types/node",
4-
"version": "20.17.9999",
4+
"version": "20.19.9999",
55
"nonNpm": "conflict",
66
"nonNpmDescription": "Node.js",
77
"projects": [
@@ -15,7 +15,7 @@
1515
}
1616
},
1717
"dependencies": {
18-
"undici-types": "~6.19.2"
18+
"undici-types": "~6.21.0"
1919
},
2020
"devDependencies": {
2121
"@types/node": "workspace:."

types/node/v20/perf_hooks.d.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,20 @@ declare module "perf_hooks" {
116116
class PerformanceMeasure extends PerformanceEntry {
117117
readonly entryType: "measure";
118118
}
119+
interface UVMetrics {
120+
/**
121+
* Number of event loop iterations.
122+
*/
123+
readonly loopCount: number;
124+
/**
125+
* Number of events that have been processed by the event handler.
126+
*/
127+
readonly events: number;
128+
/**
129+
* Number of events that were waiting to be processed when the event provider was called.
130+
*/
131+
readonly eventsWaiting: number;
132+
}
119133
/**
120134
* _This property is an extension by Node.js. It is not available in Web browsers._
121135
*
@@ -165,6 +179,16 @@ declare module "perf_hooks" {
165179
* @since v8.5.0
166180
*/
167181
readonly nodeStart: number;
182+
/**
183+
* This is a wrapper to the `uv_metrics_info` function.
184+
* It returns the current set of event loop metrics.
185+
*
186+
* It is recommended to use this property inside a function whose execution was
187+
* scheduled using `setImmediate` to avoid collecting metrics before finishing all
188+
* operations scheduled during the current loop iteration.
189+
* @since v20.18.0
190+
*/
191+
readonly uvMetricsInfo: UVMetrics;
168192
/**
169193
* The high resolution millisecond timestamp at which the V8 platform was
170194
* initialized.
@@ -563,6 +587,11 @@ declare module "perf_hooks" {
563587
buffered?: boolean | undefined;
564588
},
565589
): void;
590+
/**
591+
* @since v16.0.0
592+
* @returns Current list of entries stored in the performance observer, emptying it out.
593+
*/
594+
takeRecords(): PerformanceEntry[];
566595
}
567596
/**
568597
* Provides detailed network timing data regarding the loading of an application's resources.

types/node/v20/process.d.ts

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,59 @@ declare module "process" {
168168
libUrl?: string | undefined;
169169
lts?: string | undefined;
170170
}
171+
interface ProcessFeatures {
172+
/**
173+
* A boolean value that is `true` if the current Node.js build is caching builtin modules.
174+
* @since v12.0.0
175+
*/
176+
readonly cached_builtins: boolean;
177+
/**
178+
* A boolean value that is `true` if the current Node.js build is a debug build.
179+
* @since v0.5.5
180+
*/
181+
readonly debug: boolean;
182+
/**
183+
* A boolean value that is `true` if the current Node.js build includes the inspector.
184+
* @since v11.10.0
185+
*/
186+
readonly inspector: boolean;
187+
/**
188+
* A boolean value that is `true` if the current Node.js build includes support for IPv6.
189+
* @since v0.5.3
190+
*/
191+
readonly ipv6: boolean;
192+
/**
193+
* A boolean value that is `true` if the current Node.js build supports
194+
* [loading ECMAScript modules using `require()`](https://nodejs.org/docs/latest-v20.x/api/modules.html#loading-ecmascript-modules-using-require).
195+
* @since v20.19.0
196+
*/
197+
readonly require_module: boolean;
198+
/**
199+
* A boolean value that is `true` if the current Node.js build includes support for TLS.
200+
* @since v0.5.3
201+
*/
202+
readonly tls: boolean;
203+
/**
204+
* A boolean value that is `true` if the current Node.js build includes support for ALPN in TLS.
205+
* @since v4.8.0
206+
*/
207+
readonly tls_alpn: boolean;
208+
/**
209+
* A boolean value that is `true` if the current Node.js build includes support for OCSP in TLS.
210+
* @since v0.11.13
211+
*/
212+
readonly tls_ocsp: boolean;
213+
/**
214+
* A boolean value that is `true` if the current Node.js build includes support for SNI in TLS.
215+
* @since v0.5.3
216+
*/
217+
readonly tls_sni: boolean;
218+
/**
219+
* A boolean value that is `true` if the current Node.js build includes support for libuv.
220+
* @since v0.5.3
221+
*/
222+
readonly uv: boolean;
223+
}
171224
interface ProcessVersions extends Dict<string> {
172225
http_parser: string;
173226
node: string;
@@ -1612,16 +1665,7 @@ declare module "process" {
16121665
* @since v3.0.0
16131666
*/
16141667
readonly release: ProcessRelease;
1615-
features: {
1616-
inspector: boolean;
1617-
debug: boolean;
1618-
uv: boolean;
1619-
ipv6: boolean;
1620-
tls_alpn: boolean;
1621-
tls_sni: boolean;
1622-
tls_ocsp: boolean;
1623-
tls: boolean;
1624-
};
1668+
readonly features: ProcessFeatures;
16251669
/**
16261670
* `process.umask()` returns the Node.js process's file mode creation mask. Child
16271671
* processes inherit the mask from the parent process.

types/node/v20/test.d.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,30 @@ declare module "node:test" {
853853
type FunctionPropertyNames<T> = {
854854
[K in keyof T]: T[K] extends Function ? K : never;
855855
}[keyof T];
856+
interface MockModuleOptions {
857+
/**
858+
* If false, each call to `require()` or `import()` generates a new mock module.
859+
* If true, subsequent calls will return the same module mock, and the mock module is inserted into the CommonJS cache.
860+
* @default false
861+
*/
862+
cache?: boolean | undefined;
863+
/**
864+
* The value to use as the mocked module's default export.
865+
*
866+
* If this value is not provided, ESM mocks do not include a default export.
867+
* If the mock is a CommonJS or builtin module, this setting is used as the value of `module.exports`.
868+
* If this value is not provided, CJS and builtin mocks use an empty object as the value of `module.exports`.
869+
*/
870+
defaultExport?: any;
871+
/**
872+
* An object whose keys and values are used to create the named exports of the mock module.
873+
*
874+
* If the mock is a CommonJS or builtin module, these values are copied onto `module.exports`.
875+
* Therefore, if a mock is created with both named exports and a non-object default export,
876+
* the mock will throw an exception when used as a CJS or builtin module.
877+
*/
878+
namedExports?: object | undefined;
879+
}
856880
/**
857881
* The `MockTracker` class is used to manage mocking functionality. The test runner
858882
* module provides a top level `mock` export which is a `MockTracker` instance.
@@ -1015,6 +1039,19 @@ declare module "node:test" {
10151039
implementation?: Implementation,
10161040
options?: MockFunctionOptions,
10171041
): Mock<((value: MockedObject[MethodName]) => void) | Implementation>;
1042+
1043+
/**
1044+
* This function is used to mock the exports of ECMAScript modules, CommonJS modules, and Node.js builtin modules.
1045+
* Any references to the original module prior to mocking are not impacted.
1046+
*
1047+
* Only available through the [--experimental-test-module-mocks](https://nodejs.org/api/cli.html#--experimental-test-module-mocks) flag.
1048+
* @since v20.18.0
1049+
* @experimental
1050+
* @param specifier A string identifying the module to mock.
1051+
* @param options Optional configuration options for the mock module.
1052+
*/
1053+
module(specifier: string, options?: MockModuleOptions): MockModuleContext;
1054+
10181055
/**
10191056
* This function restores the default behavior of all mocks that were previously
10201057
* created by this `MockTracker` and disassociates the mocks from the `MockTracker` instance. Once disassociated, the mocks can still be used, but the `MockTracker` instance can no longer be
@@ -1173,6 +1210,18 @@ declare module "node:test" {
11731210
*/
11741211
restore(): void;
11751212
}
1213+
/**
1214+
* @since v20.18.0
1215+
* @experimental
1216+
*/
1217+
class MockModuleContext {
1218+
/**
1219+
* Resets the implementation of the mock module.
1220+
* @since v20.18.0
1221+
*/
1222+
restore(): void;
1223+
}
1224+
11761225
type Timer = "setInterval" | "setTimeout" | "setImmediate" | "Date";
11771226

11781227
interface MockTimersOptions {

types/node/v20/test/inspector.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,8 @@ session.on("Debugger.resumed", () => {});
6262
// $ExpectType InspectorConsole
6363
inspector.console;
6464

65+
// $ExpectType void
66+
inspector.Network.loadingFinished({ requestId: "12345", timestamp: 1234567890000 });
67+
6568
// $ExpectType Promise<EvaluateReturnType>
6669
new promiseSession().post("Runtime.evaluate", { expression: "2 + 2" });

types/node/v20/test/perf_hooks.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,14 @@ const resource = NodePerf.markResourceTiming(
151151
"",
152152
);
153153
resource; // $ExpectType PerformanceResourceTiming
154+
155+
{
156+
const { nodeTiming } = NodePerf;
157+
158+
// $ExpectType UVMetrics
159+
const uvMetrics = nodeTiming.uvMetricsInfo;
160+
161+
uvMetrics.loopCount; // $ExpectType number
162+
uvMetrics.events; // $ExpectType number
163+
uvMetrics.eventsWaiting; // $ExpectType number
164+
}

types/node/v20/test/test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,25 @@ test("mocks a setter", (t) => {
788788
}
789789
});
790790

791+
test("mocks a module", (t) => {
792+
// $ExpectType MockModuleContext
793+
const mock = t.mock.module("node:readline", {
794+
namedExports: {
795+
fn() {
796+
return 42;
797+
},
798+
},
799+
defaultExport: {
800+
foo() {
801+
return "bar";
802+
},
803+
},
804+
cache: true,
805+
});
806+
// $ExpectType void
807+
mock.restore();
808+
});
809+
791810
// @ts-expect-error
792811
dot();
793812
// $ExpectType AsyncGenerator<"\n" | "." | "X", void, unknown> || AsyncGenerator<"\n" | "." | "X", void, any>

types/node/v20/test/url.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,11 @@ import * as url from "node:url";
212212
const urlSearchParams1: URLSearchParams = new url.URLSearchParams();
213213
const urlSearchParams2: url.URLSearchParams = new URLSearchParams();
214214
}
215+
216+
{
217+
const isValid = url.URL.canParse("/foo", "https://example.org/");
218+
isValid; // $ExpectType boolean
219+
220+
const parsedUrl = url.URL.parse("/foo", "https://example.org/");
221+
parsedUrl; // $ExpectType URL | null
222+
}

0 commit comments

Comments
 (0)