zod 4.2.0-canary.20251124T022609 → 4.2.0-canary.20251207T223211
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.
- package/package.json +1 -1
- package/src/v3/tests/complex.test.ts +17 -3
- package/src/v3/tests/function.test.ts +7 -3
- package/src/v3/tests/nan.test.ts +5 -2
- package/src/v4/classic/tests/fix-json-issue.test.ts +26 -0
- package/src/v4/core/util.ts +1 -1
- package/src/v4/core/versions.ts +1 -1
- package/src/v4/mini/schemas.ts +2 -2
- package/v4/core/util.cjs +1 -1
- package/v4/core/util.js +1 -1
- package/v4/core/versions.cjs +1 -1
- package/v4/core/versions.js +1 -1
- package/v4/mini/schemas.d.cts +2 -2
- package/v4/mini/schemas.d.ts +2 -2
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { test } from "vitest";
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
2
|
import * as z from "zod/v3";
|
|
3
3
|
|
|
4
4
|
const crazySchema = z.object({
|
|
@@ -40,7 +40,7 @@ const crazySchema = z.object({
|
|
|
40
40
|
// });
|
|
41
41
|
|
|
42
42
|
test("parse", () => {
|
|
43
|
-
|
|
43
|
+
const input = {
|
|
44
44
|
tuple: ["asdf", 1234, true, null, undefined, "1234"],
|
|
45
45
|
merged: { k1: "asdf", k2: 12 },
|
|
46
46
|
union: ["asdf", 12, "asdf", 12, "asdf", 12],
|
|
@@ -52,5 +52,19 @@ test("parse", () => {
|
|
|
52
52
|
nonstrict: { points: 1234 },
|
|
53
53
|
numProm: Promise.resolve(12),
|
|
54
54
|
lenfun: (x: string) => x.length,
|
|
55
|
-
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const result = crazySchema.parse(input);
|
|
58
|
+
|
|
59
|
+
// Verify the parsed result structure
|
|
60
|
+
expect(result.tuple).toEqual(input.tuple);
|
|
61
|
+
expect(result.merged).toEqual(input.merged);
|
|
62
|
+
expect(result.union).toEqual(input.union);
|
|
63
|
+
expect(result.array).toEqual(input.array);
|
|
64
|
+
expect(result.sumMinLength).toEqual(input.sumMinLength);
|
|
65
|
+
expect(result.intersection).toEqual(input.intersection);
|
|
66
|
+
expect(result.enum).toEqual(input.enum);
|
|
67
|
+
expect(result.nonstrict).toEqual(input.nonstrict);
|
|
68
|
+
expect(result.numProm).toBeInstanceOf(Promise);
|
|
69
|
+
expect(typeof result.lenfun).toBe("function");
|
|
56
70
|
});
|
|
@@ -10,7 +10,8 @@ const func1 = z.function(args1, returns1);
|
|
|
10
10
|
|
|
11
11
|
test("function parsing", () => {
|
|
12
12
|
const parsed = func1.parse((arg: any) => arg.length);
|
|
13
|
-
parsed("asdf");
|
|
13
|
+
const result = parsed("asdf");
|
|
14
|
+
expect(result).toBe(4);
|
|
14
15
|
});
|
|
15
16
|
|
|
16
17
|
test("parsed function fail 1", () => {
|
|
@@ -226,8 +227,11 @@ test("allow extra parameters", () => {
|
|
|
226
227
|
test("params and returnType getters", () => {
|
|
227
228
|
const func = z.function().args(z.string()).returns(z.string());
|
|
228
229
|
|
|
229
|
-
func.parameters().items[0].parse("asdf");
|
|
230
|
-
|
|
230
|
+
const paramResult = func.parameters().items[0].parse("asdf");
|
|
231
|
+
expect(paramResult).toBe("asdf");
|
|
232
|
+
|
|
233
|
+
const returnResult = func.returnType().parse("asdf");
|
|
234
|
+
expect(returnResult).toBe("asdf");
|
|
231
235
|
});
|
|
232
236
|
|
|
233
237
|
test("inference with transforms", () => {
|
package/src/v3/tests/nan.test.ts
CHANGED
|
@@ -6,8 +6,11 @@ import * as z from "zod/v3";
|
|
|
6
6
|
const schema = z.nan();
|
|
7
7
|
|
|
8
8
|
test("passing validations", () => {
|
|
9
|
-
schema.parse(Number.NaN);
|
|
10
|
-
|
|
9
|
+
const result1 = schema.parse(Number.NaN);
|
|
10
|
+
expect(Number.isNaN(result1)).toBe(true);
|
|
11
|
+
|
|
12
|
+
const result2 = schema.parse(Number("Not a number"));
|
|
13
|
+
expect(Number.isNaN(result2)).toBe(true);
|
|
11
14
|
});
|
|
12
15
|
|
|
13
16
|
test("failing validations", () => {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
|
+
import { type infer as _infer, json, nullable, object, pipe, transform } from "../../mini/index.js";
|
|
3
|
+
// biome-ignore lint/correctness/noUnusedImports: This import verifies the type is exported
|
|
4
|
+
import type { _ZodMiniJSONSchema } from "../../mini/schemas.js";
|
|
5
|
+
|
|
6
|
+
const DataType = object({
|
|
7
|
+
data: json(),
|
|
8
|
+
});
|
|
9
|
+
type DataType = _infer<typeof DataType>;
|
|
10
|
+
|
|
11
|
+
// biome-ignore lint/suspicious/noExportsInTest: This export is required to reproduce TS4023
|
|
12
|
+
export const Container = object({
|
|
13
|
+
contained: pipe(
|
|
14
|
+
nullable(DataType),
|
|
15
|
+
transform<DataType | null>(
|
|
16
|
+
(v) =>
|
|
17
|
+
v ?? {
|
|
18
|
+
data: "",
|
|
19
|
+
}
|
|
20
|
+
)
|
|
21
|
+
),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("issue reproduction should compile without type errors", () => {
|
|
25
|
+
expect(Container).toBeDefined();
|
|
26
|
+
});
|
package/src/v4/core/util.ts
CHANGED
|
@@ -199,7 +199,7 @@ export function assertNotEqual<A, B>(val: AssertNotEqual<A, B>): AssertNotEqual<
|
|
|
199
199
|
export function assertIs<T>(_arg: T): void {}
|
|
200
200
|
|
|
201
201
|
export function assertNever(_x: never): never {
|
|
202
|
-
throw new Error();
|
|
202
|
+
throw new Error("Unexpected value in exhaustive check");
|
|
203
203
|
}
|
|
204
204
|
export function assert<T>(_: any): asserts _ is T {}
|
|
205
205
|
|
package/src/v4/core/versions.ts
CHANGED
package/src/v4/mini/schemas.ts
CHANGED
|
@@ -1649,7 +1649,7 @@ export const stringbool: (_params?: string | core.$ZodStringBoolParams) => ZodMi
|
|
|
1649
1649
|
// json
|
|
1650
1650
|
|
|
1651
1651
|
// json
|
|
1652
|
-
type _ZodMiniJSONSchema = ZodMiniUnion<
|
|
1652
|
+
export type _ZodMiniJSONSchema = ZodMiniUnion<
|
|
1653
1653
|
[
|
|
1654
1654
|
ZodMiniString,
|
|
1655
1655
|
ZodMiniNumber,
|
|
@@ -1659,7 +1659,7 @@ type _ZodMiniJSONSchema = ZodMiniUnion<
|
|
|
1659
1659
|
ZodMiniRecord<ZodMiniString<string>, ZodMiniJSONSchema>,
|
|
1660
1660
|
]
|
|
1661
1661
|
>;
|
|
1662
|
-
type _ZodMiniJSONSchemaInternals = _ZodMiniJSONSchema["_zod"];
|
|
1662
|
+
export type _ZodMiniJSONSchemaInternals = _ZodMiniJSONSchema["_zod"];
|
|
1663
1663
|
|
|
1664
1664
|
export interface ZodMiniJSONSchemaInternals extends _ZodMiniJSONSchemaInternals {
|
|
1665
1665
|
output: util.JSONType;
|
package/v4/core/util.cjs
CHANGED
package/v4/core/util.js
CHANGED
|
@@ -7,7 +7,7 @@ export function assertNotEqual(val) {
|
|
|
7
7
|
}
|
|
8
8
|
export function assertIs(_arg) { }
|
|
9
9
|
export function assertNever(_x) {
|
|
10
|
-
throw new Error();
|
|
10
|
+
throw new Error("Unexpected value in exhaustive check");
|
|
11
11
|
}
|
|
12
12
|
export function assert(_) { }
|
|
13
13
|
export function getEnumValues(entries) {
|
package/v4/core/versions.cjs
CHANGED
package/v4/core/versions.js
CHANGED
package/v4/mini/schemas.d.cts
CHANGED
|
@@ -365,7 +365,7 @@ declare abstract class Class {
|
|
|
365
365
|
declare function _instanceof<T extends typeof Class>(cls: T, params?: core.$ZodCustomParams): ZodMiniCustom<InstanceType<T>, InstanceType<T>>;
|
|
366
366
|
export { _instanceof as instanceof };
|
|
367
367
|
export declare const stringbool: (_params?: string | core.$ZodStringBoolParams) => ZodMiniCodec<ZodMiniString, ZodMiniBoolean>;
|
|
368
|
-
type _ZodMiniJSONSchema = ZodMiniUnion<[
|
|
368
|
+
export type _ZodMiniJSONSchema = ZodMiniUnion<[
|
|
369
369
|
ZodMiniString,
|
|
370
370
|
ZodMiniNumber,
|
|
371
371
|
ZodMiniBoolean,
|
|
@@ -373,7 +373,7 @@ type _ZodMiniJSONSchema = ZodMiniUnion<[
|
|
|
373
373
|
ZodMiniArray<ZodMiniJSONSchema>,
|
|
374
374
|
ZodMiniRecord<ZodMiniString<string>, ZodMiniJSONSchema>
|
|
375
375
|
]>;
|
|
376
|
-
type _ZodMiniJSONSchemaInternals = _ZodMiniJSONSchema["_zod"];
|
|
376
|
+
export type _ZodMiniJSONSchemaInternals = _ZodMiniJSONSchema["_zod"];
|
|
377
377
|
export interface ZodMiniJSONSchemaInternals extends _ZodMiniJSONSchemaInternals {
|
|
378
378
|
output: util.JSONType;
|
|
379
379
|
input: util.JSONType;
|
package/v4/mini/schemas.d.ts
CHANGED
|
@@ -365,7 +365,7 @@ declare abstract class Class {
|
|
|
365
365
|
declare function _instanceof<T extends typeof Class>(cls: T, params?: core.$ZodCustomParams): ZodMiniCustom<InstanceType<T>, InstanceType<T>>;
|
|
366
366
|
export { _instanceof as instanceof };
|
|
367
367
|
export declare const stringbool: (_params?: string | core.$ZodStringBoolParams) => ZodMiniCodec<ZodMiniString, ZodMiniBoolean>;
|
|
368
|
-
type _ZodMiniJSONSchema = ZodMiniUnion<[
|
|
368
|
+
export type _ZodMiniJSONSchema = ZodMiniUnion<[
|
|
369
369
|
ZodMiniString,
|
|
370
370
|
ZodMiniNumber,
|
|
371
371
|
ZodMiniBoolean,
|
|
@@ -373,7 +373,7 @@ type _ZodMiniJSONSchema = ZodMiniUnion<[
|
|
|
373
373
|
ZodMiniArray<ZodMiniJSONSchema>,
|
|
374
374
|
ZodMiniRecord<ZodMiniString<string>, ZodMiniJSONSchema>
|
|
375
375
|
]>;
|
|
376
|
-
type _ZodMiniJSONSchemaInternals = _ZodMiniJSONSchema["_zod"];
|
|
376
|
+
export type _ZodMiniJSONSchemaInternals = _ZodMiniJSONSchema["_zod"];
|
|
377
377
|
export interface ZodMiniJSONSchemaInternals extends _ZodMiniJSONSchemaInternals {
|
|
378
378
|
output: util.JSONType;
|
|
379
379
|
input: util.JSONType;
|