zod 4.1.0-canary.20250710T223408 → 4.1.0-canary.20250711T200924
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/v4/classic/schemas.ts +1 -0
- package/src/v4/classic/tests/catch.test.ts +4 -5
- package/src/v4/classic/tests/discriminated-unions.test.ts +12 -0
- package/src/v4/core/schemas.ts +1 -4
- package/src/v4/core/versions.ts +1 -1
- package/v4/classic/schemas.d.cts +1 -0
- package/v4/classic/schemas.d.ts +1 -0
- package/v4/core/schemas.d.cts +1 -1
- package/v4/core/schemas.d.ts +1 -1
- package/v4/core/versions.cjs +1 -1
- package/v4/core/versions.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zod",
|
|
3
|
-
"version": "4.1.0-canary.
|
|
3
|
+
"version": "4.1.0-canary.20250711T200924",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "Colin McDonnell <zod@colinhacks.com>",
|
|
6
6
|
"description": "TypeScript-first schema declaration and validation library with static type inference",
|
|
@@ -1224,6 +1224,7 @@ export interface ZodDiscriminatedUnion<Options extends readonly core.SomeType[]
|
|
|
1224
1224
|
extends ZodUnion<Options>,
|
|
1225
1225
|
core.$ZodDiscriminatedUnion<Options> {
|
|
1226
1226
|
_zod: core.$ZodDiscriminatedUnionInternals<Options>;
|
|
1227
|
+
def: core.$ZodDiscriminatedUnionDef<Options>;
|
|
1227
1228
|
}
|
|
1228
1229
|
export const ZodDiscriminatedUnion: core.$constructor<ZodDiscriminatedUnion> = /*@__PURE__*/ core.$constructor(
|
|
1229
1230
|
"ZodDiscriminatedUnion",
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { expect, expectTypeOf, test } from "vitest";
|
|
2
2
|
import { z } from "zod/v4";
|
|
3
|
-
import type { util } from "zod/v4/core";
|
|
4
3
|
|
|
5
4
|
test("basic catch", () => {
|
|
6
5
|
expect(z.string().catch("default").parse(undefined)).toBe("default");
|
|
@@ -45,7 +44,7 @@ test("catch with transform", () => {
|
|
|
45
44
|
expect(stringWithDefault.unwrap().out).toBeInstanceOf(z.ZodTransform);
|
|
46
45
|
|
|
47
46
|
type inp = z.input<typeof stringWithDefault>;
|
|
48
|
-
expectTypeOf<inp>().toEqualTypeOf<string
|
|
47
|
+
expectTypeOf<inp>().toEqualTypeOf<string>();
|
|
49
48
|
type out = z.output<typeof stringWithDefault>;
|
|
50
49
|
expectTypeOf<out>().toEqualTypeOf<string>();
|
|
51
50
|
});
|
|
@@ -59,7 +58,7 @@ test("catch on existing optional", () => {
|
|
|
59
58
|
expect(stringWithDefault.unwrap().unwrap()).toBeInstanceOf(z.ZodString);
|
|
60
59
|
|
|
61
60
|
type inp = z.input<typeof stringWithDefault>;
|
|
62
|
-
expectTypeOf<inp>().toEqualTypeOf<string | undefined
|
|
61
|
+
expectTypeOf<inp>().toEqualTypeOf<string | undefined>();
|
|
63
62
|
type out = z.output<typeof stringWithDefault>;
|
|
64
63
|
expectTypeOf<out>().toEqualTypeOf<string | undefined>();
|
|
65
64
|
});
|
|
@@ -68,7 +67,7 @@ test("optional on catch", () => {
|
|
|
68
67
|
const stringWithDefault = z.string().catch("asdf").optional();
|
|
69
68
|
|
|
70
69
|
type inp = z.input<typeof stringWithDefault>;
|
|
71
|
-
expectTypeOf<inp>().toEqualTypeOf<string |
|
|
70
|
+
expectTypeOf<inp>().toEqualTypeOf<string | undefined>();
|
|
72
71
|
type out = z.output<typeof stringWithDefault>;
|
|
73
72
|
expectTypeOf<out>().toEqualTypeOf<string | undefined>();
|
|
74
73
|
});
|
|
@@ -102,7 +101,7 @@ test("nested", () => {
|
|
|
102
101
|
inner: "asdf",
|
|
103
102
|
});
|
|
104
103
|
type input = z.input<typeof outer>;
|
|
105
|
-
expectTypeOf<input>().toEqualTypeOf<{ inner: string
|
|
104
|
+
expectTypeOf<input>().toEqualTypeOf<{ inner: string }>();
|
|
106
105
|
type out = z.output<typeof outer>;
|
|
107
106
|
|
|
108
107
|
expectTypeOf<out>().toEqualTypeOf<{ inner: string }>();
|
|
@@ -646,3 +646,15 @@ test("pipes", () => {
|
|
|
646
646
|
v: 2,
|
|
647
647
|
});
|
|
648
648
|
});
|
|
649
|
+
|
|
650
|
+
test("def", () => {
|
|
651
|
+
const schema = z.discriminatedUnion(
|
|
652
|
+
"type",
|
|
653
|
+
[z.object({ type: z.literal("play") }), z.object({ type: z.literal("pause") })],
|
|
654
|
+
{ unionFallback: true }
|
|
655
|
+
);
|
|
656
|
+
|
|
657
|
+
expect(schema.def).toBeDefined();
|
|
658
|
+
expect(schema.def.discriminator).toEqual("type");
|
|
659
|
+
expect(schema.def.unionFallback).toEqual(true);
|
|
660
|
+
});
|
package/src/v4/core/schemas.ts
CHANGED
|
@@ -3315,11 +3315,8 @@ export interface $ZodCatchDef<T extends SomeType = $ZodType> extends $ZodTypeDef
|
|
|
3315
3315
|
}
|
|
3316
3316
|
|
|
3317
3317
|
export interface $ZodCatchInternals<T extends SomeType = $ZodType>
|
|
3318
|
-
extends $ZodTypeInternals<core.output<T>, core.input<T
|
|
3318
|
+
extends $ZodTypeInternals<core.output<T>, core.input<T>> {
|
|
3319
3319
|
def: $ZodCatchDef<T>;
|
|
3320
|
-
// qin: T["_zod"]["qin"];
|
|
3321
|
-
// qout: T["_zod"]["qout"];
|
|
3322
|
-
|
|
3323
3320
|
optin: T["_zod"]["optin"];
|
|
3324
3321
|
optout: T["_zod"]["optout"];
|
|
3325
3322
|
isst: never;
|
package/src/v4/core/versions.ts
CHANGED
package/v4/classic/schemas.d.cts
CHANGED
|
@@ -446,6 +446,7 @@ export declare const ZodUnion: core.$constructor<ZodUnion>;
|
|
|
446
446
|
export declare function union<const T extends readonly core.SomeType[]>(options: T, params?: string | core.$ZodUnionParams): ZodUnion<T>;
|
|
447
447
|
export interface ZodDiscriminatedUnion<Options extends readonly core.SomeType[] = readonly core.$ZodType[]> extends ZodUnion<Options>, core.$ZodDiscriminatedUnion<Options> {
|
|
448
448
|
_zod: core.$ZodDiscriminatedUnionInternals<Options>;
|
|
449
|
+
def: core.$ZodDiscriminatedUnionDef<Options>;
|
|
449
450
|
}
|
|
450
451
|
export declare const ZodDiscriminatedUnion: core.$constructor<ZodDiscriminatedUnion>;
|
|
451
452
|
export declare function discriminatedUnion<Types extends readonly [core.$ZodTypeDiscriminable, ...core.$ZodTypeDiscriminable[]]>(discriminator: string, options: Types, params?: string | core.$ZodDiscriminatedUnionParams): ZodDiscriminatedUnion<Types>;
|
package/v4/classic/schemas.d.ts
CHANGED
|
@@ -446,6 +446,7 @@ export declare const ZodUnion: core.$constructor<ZodUnion>;
|
|
|
446
446
|
export declare function union<const T extends readonly core.SomeType[]>(options: T, params?: string | core.$ZodUnionParams): ZodUnion<T>;
|
|
447
447
|
export interface ZodDiscriminatedUnion<Options extends readonly core.SomeType[] = readonly core.$ZodType[]> extends ZodUnion<Options>, core.$ZodDiscriminatedUnion<Options> {
|
|
448
448
|
_zod: core.$ZodDiscriminatedUnionInternals<Options>;
|
|
449
|
+
def: core.$ZodDiscriminatedUnionDef<Options>;
|
|
449
450
|
}
|
|
450
451
|
export declare const ZodDiscriminatedUnion: core.$constructor<ZodDiscriminatedUnion>;
|
|
451
452
|
export declare function discriminatedUnion<Types extends readonly [core.$ZodTypeDiscriminable, ...core.$ZodTypeDiscriminable[]]>(discriminator: string, options: Types, params?: string | core.$ZodDiscriminatedUnionParams): ZodDiscriminatedUnion<Types>;
|
package/v4/core/schemas.d.cts
CHANGED
|
@@ -902,7 +902,7 @@ export interface $ZodCatchDef<T extends SomeType = $ZodType> extends $ZodTypeDef
|
|
|
902
902
|
innerType: T;
|
|
903
903
|
catchValue: (ctx: $ZodCatchCtx) => unknown;
|
|
904
904
|
}
|
|
905
|
-
export interface $ZodCatchInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<core.output<T>, core.input<T
|
|
905
|
+
export interface $ZodCatchInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<core.output<T>, core.input<T>> {
|
|
906
906
|
def: $ZodCatchDef<T>;
|
|
907
907
|
optin: T["_zod"]["optin"];
|
|
908
908
|
optout: T["_zod"]["optout"];
|
package/v4/core/schemas.d.ts
CHANGED
|
@@ -902,7 +902,7 @@ export interface $ZodCatchDef<T extends SomeType = $ZodType> extends $ZodTypeDef
|
|
|
902
902
|
innerType: T;
|
|
903
903
|
catchValue: (ctx: $ZodCatchCtx) => unknown;
|
|
904
904
|
}
|
|
905
|
-
export interface $ZodCatchInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<core.output<T>, core.input<T
|
|
905
|
+
export interface $ZodCatchInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<core.output<T>, core.input<T>> {
|
|
906
906
|
def: $ZodCatchDef<T>;
|
|
907
907
|
optin: T["_zod"]["optin"];
|
|
908
908
|
optout: T["_zod"]["optout"];
|
package/v4/core/versions.cjs
CHANGED
package/v4/core/versions.js
CHANGED