Skip to content

Commit c1d22eb

Browse files
authored
🤖 Merge PR DefinitelyTyped#73937 node: v22.19 by @Renegade334
1 parent d9e0e0e commit c1d22eb

27 files changed

+1405
-1051
lines changed

types/node/v22/assert.d.ts

Lines changed: 100 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
* @see [source](https://github.com/nodejs/node/blob/v22.x/lib/assert.js)
55
*/
66
declare module "assert" {
7+
import strict = require("assert/strict");
78
/**
8-
* An alias of {@link ok}.
9+
* An alias of {@link assert.ok}.
910
* @since v0.5.9
1011
* @param value The input that is checked for being truthy.
1112
*/
1213
function assert(value: unknown, message?: string | Error): asserts value;
14+
const kOptions: unique symbol;
1315
namespace assert {
1416
type AssertMethodNames =
1517
| "deepEqual"
@@ -30,10 +32,100 @@ declare module "assert" {
3032
| "rejects"
3133
| "strictEqual"
3234
| "throws";
35+
interface AssertOptions {
36+
/**
37+
* If set to `'full'`, shows the full diff in assertion errors.
38+
* @default 'simple'
39+
*/
40+
diff?: "simple" | "full" | undefined;
41+
/**
42+
* If set to `true`, non-strict methods behave like their
43+
* corresponding strict methods.
44+
* @default true
45+
*/
46+
strict?: boolean | undefined;
47+
}
48+
interface Assert extends Pick<typeof assert, AssertMethodNames> {
49+
readonly [kOptions]: AssertOptions & { strict: false };
50+
}
51+
interface AssertStrict extends Pick<typeof strict, AssertMethodNames> {
52+
readonly [kOptions]: AssertOptions & { strict: true };
53+
}
54+
/**
55+
* The `Assert` class allows creating independent assertion instances with custom options.
56+
* @since v22.19.0
57+
*/
58+
var Assert: {
59+
/**
60+
* Creates a new assertion instance. The `diff` option controls the verbosity of diffs in assertion error messages.
61+
*
62+
* ```js
63+
* const { Assert } = require('node:assert');
64+
* const assertInstance = new Assert({ diff: 'full' });
65+
* assertInstance.deepStrictEqual({ a: 1 }, { a: 2 });
66+
* // Shows a full diff in the error message.
67+
* ```
68+
*
69+
* **Important**: When destructuring assertion methods from an `Assert` instance,
70+
* the methods lose their connection to the instance's configuration options (such as `diff` and `strict` settings).
71+
* The destructured methods will fall back to default behavior instead.
72+
*
73+
* ```js
74+
* const myAssert = new Assert({ diff: 'full' });
75+
*
76+
* // This works as expected - uses 'full' diff
77+
* myAssert.strictEqual({ a: 1 }, { b: { c: 1 } });
78+
*
79+
* // This loses the 'full' diff setting - falls back to default 'simple' diff
80+
* const { strictEqual } = myAssert;
81+
* strictEqual({ a: 1 }, { b: { c: 1 } });
82+
* ```
83+
*
84+
* When destructured, methods lose access to the instance's `this` context and revert to default assertion behavior
85+
* (diff: 'simple', non-strict mode).
86+
* To maintain custom options when using destructured methods, avoid
87+
* destructuring and call methods directly on the instance.
88+
* @since v22.19.0
89+
*/
90+
new(
91+
options?: AssertOptions & { strict?: true },
92+
): AssertStrict;
93+
new(
94+
options: AssertOptions,
95+
): Assert;
96+
};
97+
interface AssertionErrorOptions {
98+
/**
99+
* If provided, the error message is set to this value.
100+
*/
101+
message?: string | undefined;
102+
/**
103+
* The `actual` property on the error instance.
104+
*/
105+
actual?: unknown;
106+
/**
107+
* The `expected` property on the error instance.
108+
*/
109+
expected?: unknown;
110+
/**
111+
* The `operator` property on the error instance.
112+
*/
113+
operator?: string | undefined;
114+
/**
115+
* If provided, the generated stack trace omits frames before this function.
116+
*/
117+
stackStartFn?: Function | undefined;
118+
/**
119+
* If set to `'full'`, shows the full diff in assertion errors.
120+
* @default 'simple'
121+
*/
122+
diff?: "simple" | "full" | undefined;
123+
}
33124
/**
34125
* Indicates the failure of an assertion. All errors thrown by the `node:assert` module will be instances of the `AssertionError` class.
35126
*/
36127
class AssertionError extends Error {
128+
constructor(options: AssertionErrorOptions);
37129
/**
38130
* Set to the `actual` argument for methods such as {@link assert.strictEqual()}.
39131
*/
@@ -42,10 +134,6 @@ declare module "assert" {
42134
* Set to the `expected` argument for methods such as {@link assert.strictEqual()}.
43135
*/
44136
expected: unknown;
45-
/**
46-
* Set to the passed in operator value.
47-
*/
48-
operator: string;
49137
/**
50138
* Indicates if the message was auto-generated (`true`) or not.
51139
*/
@@ -54,19 +142,10 @@ declare module "assert" {
54142
* Value is always `ERR_ASSERTION` to show that the error is an assertion error.
55143
*/
56144
code: "ERR_ASSERTION";
57-
constructor(options?: {
58-
/** If provided, the error message is set to this value. */
59-
message?: string | undefined;
60-
/** The `actual` property on the error instance. */
61-
actual?: unknown | undefined;
62-
/** The `expected` property on the error instance. */
63-
expected?: unknown | undefined;
64-
/** The `operator` property on the error instance. */
65-
operator?: string | undefined;
66-
/** If provided, the generated stack trace omits frames before this function. */
67-
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
68-
stackStartFn?: Function | undefined;
69-
});
145+
/**
146+
* Set to the passed in operator value.
147+
*/
148+
operator: string;
70149
}
71150
/**
72151
* This feature is deprecated and will be removed in a future version.
@@ -987,83 +1066,9 @@ declare module "assert" {
9871066
* @since v22.13.0
9881067
*/
9891068
function partialDeepStrictEqual(actual: unknown, expected: unknown, message?: string | Error): void;
990-
/**
991-
* In strict assertion mode, non-strict methods behave like their corresponding strict methods. For example,
992-
* {@link deepEqual} will behave like {@link deepStrictEqual}.
993-
*
994-
* In strict assertion mode, error messages for objects display a diff. In legacy assertion mode, error
995-
* messages for objects display the objects, often truncated.
996-
*
997-
* To use strict assertion mode:
998-
*
999-
* ```js
1000-
* import { strict as assert } from 'node:assert';
1001-
* import assert from 'node:assert/strict';
1002-
* ```
1003-
*
1004-
* Example error diff:
1005-
*
1006-
* ```js
1007-
* import { strict as assert } from 'node:assert';
1008-
*
1009-
* assert.deepEqual([[[1, 2, 3]], 4, 5], [[[1, 2, '3']], 4, 5]);
1010-
* // AssertionError: Expected inputs to be strictly deep-equal:
1011-
* // + actual - expected ... Lines skipped
1012-
* //
1013-
* // [
1014-
* // [
1015-
* // ...
1016-
* // 2,
1017-
* // + 3
1018-
* // - '3'
1019-
* // ],
1020-
* // ...
1021-
* // 5
1022-
* // ]
1023-
* ```
1024-
*
1025-
* To deactivate the colors, use the `NO_COLOR` or `NODE_DISABLE_COLORS` environment variables. This will also
1026-
* deactivate the colors in the REPL. For more on color support in terminal environments, read the tty
1027-
* `getColorDepth()` documentation.
1028-
*
1029-
* @since v15.0.0, v13.9.0, v12.16.2, v9.9.0
1030-
*/
1031-
namespace strict {
1032-
type AssertionError = assert.AssertionError;
1033-
type AssertPredicate = assert.AssertPredicate;
1034-
type CallTrackerCall = assert.CallTrackerCall;
1035-
type CallTrackerReportInformation = assert.CallTrackerReportInformation;
1036-
}
1037-
const strict:
1038-
& Omit<
1039-
typeof assert,
1040-
| "equal"
1041-
| "notEqual"
1042-
| "deepEqual"
1043-
| "notDeepEqual"
1044-
| "ok"
1045-
| "strictEqual"
1046-
| "deepStrictEqual"
1047-
| "ifError"
1048-
| "strict"
1049-
| "AssertionError"
1050-
>
1051-
& {
1052-
(value: unknown, message?: string | Error): asserts value;
1053-
equal: typeof strictEqual;
1054-
notEqual: typeof notStrictEqual;
1055-
deepEqual: typeof deepStrictEqual;
1056-
notDeepEqual: typeof notDeepStrictEqual;
1057-
// Mapped types and assertion functions are incompatible?
1058-
// TS2775: Assertions require every name in the call target
1059-
// to be declared with an explicit type annotation.
1060-
ok: typeof ok;
1061-
strictEqual: typeof strictEqual;
1062-
deepStrictEqual: typeof deepStrictEqual;
1063-
ifError: typeof ifError;
1064-
strict: typeof strict;
1065-
AssertionError: typeof AssertionError;
1066-
};
1069+
}
1070+
namespace assert {
1071+
export { strict };
10671072
}
10681073
export = assert;
10691074
}

types/node/v22/assert/strict.d.ts

Lines changed: 105 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,111 @@
1+
/**
2+
* In strict assertion mode, non-strict methods behave like their corresponding
3+
* strict methods. For example, `assert.deepEqual()` will behave like
4+
* `assert.deepStrictEqual()`.
5+
*
6+
* In strict assertion mode, error messages for objects display a diff. In legacy
7+
* assertion mode, error messages for objects display the objects, often truncated.
8+
*
9+
* To use strict assertion mode:
10+
*
11+
* ```js
12+
* import { strict as assert } from 'node:assert';
13+
* ```
14+
*
15+
* ```js
16+
* import assert from 'node:assert/strict';
17+
* ```
18+
*
19+
* Example error diff:
20+
*
21+
* ```js
22+
* import { strict as assert } from 'node:assert';
23+
*
24+
* assert.deepEqual([[[1, 2, 3]], 4, 5], [[[1, 2, '3']], 4, 5]);
25+
* // AssertionError: Expected inputs to be strictly deep-equal:
26+
* // + actual - expected ... Lines skipped
27+
* //
28+
* // [
29+
* // [
30+
* // ...
31+
* // 2,
32+
* // + 3
33+
* // - '3'
34+
* // ],
35+
* // ...
36+
* // 5
37+
* // ]
38+
* ```
39+
*
40+
* To deactivate the colors, use the `NO_COLOR` or `NODE_DISABLE_COLORS`
41+
* environment variables. This will also deactivate the colors in the REPL. For
42+
* more on color support in terminal environments, read the tty
43+
* [`getColorDepth()`](https://nodejs.org/docs/latest-v22.x/api/tty.html#writestreamgetcolordepthenv) documentation.
44+
* @since v15.0.0
45+
* @see [source](https://github.com/nodejs/node/blob/v22.x/lib/assert/strict.js)
46+
*/
147
declare module "assert/strict" {
2-
import { strict } from "node:assert";
48+
import {
49+
Assert,
50+
AssertionError,
51+
AssertionErrorOptions,
52+
AssertOptions,
53+
AssertPredicate,
54+
AssertStrict,
55+
CallTracker,
56+
CallTrackerCall,
57+
CallTrackerReportInformation,
58+
deepStrictEqual,
59+
doesNotMatch,
60+
doesNotReject,
61+
doesNotThrow,
62+
fail,
63+
ifError,
64+
match,
65+
notDeepStrictEqual,
66+
notStrictEqual,
67+
ok,
68+
partialDeepStrictEqual,
69+
rejects,
70+
strictEqual,
71+
throws,
72+
} from "node:assert";
73+
function strict(value: unknown, message?: string | Error): asserts value;
74+
namespace strict {
75+
export {
76+
Assert,
77+
AssertionError,
78+
AssertionErrorOptions,
79+
AssertOptions,
80+
AssertPredicate,
81+
AssertStrict,
82+
CallTracker,
83+
CallTrackerCall,
84+
CallTrackerReportInformation,
85+
deepStrictEqual,
86+
deepStrictEqual as deepEqual,
87+
doesNotMatch,
88+
doesNotReject,
89+
doesNotThrow,
90+
fail,
91+
ifError,
92+
match,
93+
notDeepStrictEqual,
94+
notDeepStrictEqual as notDeepEqual,
95+
notStrictEqual,
96+
notStrictEqual as notEqual,
97+
ok,
98+
partialDeepStrictEqual,
99+
rejects,
100+
strict,
101+
strictEqual,
102+
strictEqual as equal,
103+
throws,
104+
};
105+
}
3106
export = strict;
4107
}
5108
declare module "node:assert/strict" {
6-
import { strict } from "node:assert";
109+
import strict = require("assert/strict");
7110
export = strict;
8111
}

types/node/v22/dns.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,11 @@ declare module "dns" {
830830
* @default 4
831831
*/
832832
tries?: number | undefined;
833+
/**
834+
* The max retry timeout, in milliseconds.
835+
* @default 0
836+
*/
837+
maxTimeout?: number | undefined;
833838
}
834839
/**
835840
* An independent resolver for DNS requests.

0 commit comments

Comments
 (0)