Open brenfwd opened 4 months ago
Consider this example:
import { z } from "zod"; const FooASchema = z.object({ type: z.literal("A"), a: z.number(), }); const FooBSchema = z.object({ type: z.literal("B"), b: z.number(), }); // const FooSchema = z.union([FooASchema, FooBSchema]); const PartialFooSchema = z.union([FooASchema.partial(), FooBSchema.partial()]); const input: unknown = { b: 12 }; const typed = PartialFooSchema.safeParse(input); console.log("Input:", input); console.log("Error:", typed.error); console.log("Data:", typed.data);
Here I would expect that typed.data would be { b: 12 } since input should validate against FooBSchema.partial(). However, the actual behavior is (1) no error; and (2) typed.data is {}.
typed.data
{ b: 12 }
input
FooBSchema.partial()
{}
Hi, i have the same issue. Is there any solution? Thanks :)
Consider this example:
Here I would expect that
typed.data
would be{ b: 12 }
sinceinput
should validate againstFooBSchema.partial()
. However, the actual behavior is (1) no error; and (2)typed.data
is{}
.