-
-
Notifications
You must be signed in to change notification settings - Fork 268
Change object
and optional
to support exact optional props
#1013
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
commit: |
f259bd2
to
6a4947b
Compare
Seems mostly good, but optional defaults are broken: > v.parse(v.object({ a: v.optional(v.string(), "foo") }), {})
{} (expected |
I think this is fixed now. I also added support for the The new behavior (these are breaking changes) of this PR is as follows:
Example: const Schema = v.object({
// Disallow missing keys
key0: v.number(), // number
key1: v.undefinedable(v.number()), // number | undefined
key2: v.nullable(v.number()), // number | null
key3: v.unknown(), // unknown
// Allow missing keys
key4: v.optional(v.number()), // number
key5: v.optional(v.undefinedable(v.number())), // number | undefined
key6: v.nullish(v.number()), // number | undefined | null
key7: v.optional(v.unknown()) // unknown
}); If we think this is the right solution for Valibot, I would also update these changes in |
I have implemented your feedback and removed support for missing keys when using the Furthermore, I refactored the implementation of the I think this PR is going in the right direction. My next steps are to apply these changes to the entire codebase and update our tests. Once this PR is done, I will probably create a GitHub discussion to explain these changes and reach out to the community and ask for feedback. |
object
and optional
to support exact optional props
Please discuss with use in #1022. |
I followed @xcfox's idea: #1022 (comment) |
Valibot v1.0.0-beta.13 is available |
FIx #983