-
-
Notifications
You must be signed in to change notification settings - Fork 163
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
[feat]: Parse schema with partial fallback values #155
Comments
Maybe with const schema = object({
name: optional(string(), 'test'),
age: number(),
}); |
My goal is to extract all default values. Your suggestion changes on the one hand the typing of the inferred model. On the other hand, it is not possible to parse it, because the property I want to get an object which includes just the fallback values and the type should be |
For what exactly do you need the fallback values? Technically this is possible, but not that easy. Especially it is difficult to make it type safe. |
My intention is, that I can parse a schema, where some of the properties have a fallback value, and some not. From this schema I want to extract, only the properties which has a fallback value, into an object. All other properties, which have no fallback value, should be undefined in the extracted object. As background, I want to use Your suggested solution with optional does not work, because if I call |
|
Thanks for your detailed explanation. Then I will implement a custom logic in my project. I thought, such a functionality could maybe be helpful for other users. |
Yes, feel free to share your implementation. Maybe I will integrate it in |
Were you able to find a solution to your problem? |
Creates a default object from a given object schema. The object will contain possible default values that could have been derived from default or fallback values.
I created a PR (#169) for that feature. Happy to hear what you think about it! |
I have implemented |
v0.20.0 is now available |
Awesome thank you! In the end the |
It would be nice to have a functionality to parse a schema with partial fallback values.
For example, that this input:
results in this output:
Or is such a scenario already possible by combining multiple functions together?
As idea, I implemented here a custom version of partial, which uses
fallback
instead ofoptional
:https://stackblitz.com/edit/valibot-partial-fallback-example
The text was updated successfully, but these errors were encountered: