-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.strict()
and .and()
combined is not working
#390
Comments
This is expected. The If you're just looking to merge two objects, use const a = z.object({ a: z.string() });
const b = z.object({ b: z.string() });
const c = a.merge(b).strict(); Small side-note, when doing |
Thanks for the explanations. Sadly, this const a = z.object({ a: z.string(), b: z.number() });
const b = z.object({ b: z.string() });
const c = a.merge(b).strict(); // { a: string; b: never }
// Passed
c.parse({ a: "test", b: "42" });
// Failed
c.parse({ a: "test", b: 42 }); The Anyway, I can't use this |
Good catch! I relatively recently changed the behavior of "merge" to behave more like "extend". I forgot to update the inferred type. Fixed in alpha.38. Like you say, merge isn't an intersection, it just merges the sets of properties from A and B into a new object. In the case of a clash, the properties of B override the properties of A. I guess there isn't a way do what you're trying to do. You'll have to get rid of the Is there a reason you need strict checking? I'd recommend against having ts-to-zod generate strict ZodObjects by default, but it's totally your call. |
By the way, I just added an Ecosystem section to the README to boost projects like yours: https://github.com/colinhacks/zod/tree/v3#ecosystem |
No reason at all, was just to be "feature complete", but I will probably drop this idea (and my plan was to put this an option, not the default) |
Gotcha. Loving your work on this so far! Sorry it took so long to respond here, just started a new job. Should be more responsive in the future. Feel free to DM me on Twitter @colinhacks as well for a speedier response. |
Don't worry, I also have a lot of work and I totally understand than side-projects are not always a priority (and can be sometime hard to manage on top of all other stuff going on 😅 ) |
After #166, we moved to using strict objects by default. Apparently creating intersections between two strict objects (e.g. `braintrustModelParamsSchema` and `openAIModelParamsSchema`) doesn't seem to work at all. We have to use `merge` to make everything work. See colinhacks/zod#390 for an explanation of the issue.
After #166, we moved to using strict objects by default. Apparently creating intersections between two strict objects (e.g. `braintrustModelParamsSchema` and `openAIModelParamsSchema`) doesn't seem to work at all. We have to use `merge` to make everything work. See colinhacks/zod#390 for an explanation of the issue.
Bug description
The method
.strict()
and.and()
combined results in an unexpected parsing error.Zod version
3.0.0-alpha.33
Playground
Output
The text was updated successfully, but these errors were encountered: