Replies: 1 comment
-
|
@fabian-hiller |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'll start with a simple example:
So the inferred input type is stricter than what safeParse will allow.
This bug (in my opinion) is also reflected in the intersection docs: https://valibot.dev/guides/intersections/, which further suggests that the implementation is not in line with people's intuition about how it should work:
These docs use the following example:
but in reality we get:
because when parsing, it will not complain about extra properties, whereas the typescript compiler would complain about extra properties in the first version.
This gets worse when using a strictObject:
This is not inline with the inferred types, but also unintuitive (as well as useless) from a user perspective.
(Unfortunately zod has the exact same bug)
REMARK: if this is how it is supposed to work, then
toJsonSchemashould also be updated to avoid simply producing{ allOf: [ { additionalProperties: false }, { ... } ] }as that would have the same problem.I let Github Copilot crunch on the issue to make it behave the way I would expect it to behave: https://github.com/mrft/valibot/tree/feat-intersect-strict
Beta Was this translation helpful? Give feedback.
All reactions