-
When creating a new schema using object spread with .shape, Zod does not validate the fields inherited from the spread schema.
❌ Actual Behavior: This works as expected in zod/v4, but fails silently in zod/v4-mini — possibly due to excluded type metadata or shape internals. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hi @I-am-tk! I'm Dosu and I’m helping the zod team. This is a known limitation of To combine schemas in import { z } from "zod/v4-mini";
const Dog = z.object({
name: z.string(),
age: z.optional(z.number()),
});
const DogWithBreed = z.extend(Dog, {
breed: z.string(),
});
// This will now correctly fail if "name" is missing
console.log(
DogWithBreed.safeParse({
age: 3,
breed: "Labrador Retriever",
}),
); Or, if you need to combine more complex schemas, Let me know if this solves your problem or if you have more questions! If this answers your question, please feel free to close the issue. To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
Dog.shape
is undefined at runtime, despite being declared in the type declarations. This is a clear bug. Either it needs to be defined at runtime, or it needs to be removed from the type declarations. I’ve filed this as #4727.