Open
Conversation
Relates to the discussion in open-circle#1207 Though I'm thinking this issue might relate to multiple (or all) schemas where undefined is the desired default? If so, is there a better place to document this?
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Member
fabian-hiller
left a comment
There was a problem hiding this comment.
Feel free to also add it to nullish.
Maybe should also add a little info to the default value section of the optionals guide.
|
|
||
| ### Default to `undefined` | ||
|
|
||
| If you wish optional entries to default to an `undefined` value, you must pass the `default_` parameter as a function returning `undefined`, otherwise this will be seen as no parameter being passed. |
Member
There was a problem hiding this comment.
Should we change it to "If you wish missing object entries to default to an undefined value, ..."?
| }); | ||
| const res = v.parse(OptionalEntrySchema, {}); | ||
| // res = { key: undefined }; | ||
| ``` |
Member
There was a problem hiding this comment.
I think I would just write this to be consistent with the other example. But I see why you added it.
const OptionalEntrySchema = v.object({
key: v.optional(v.string(), () => undefined),
});
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What it does
Adds an example of setting a default of
undefinedfor the optional schema, which came from discussion in #1207.Open qus
This way of setting undefined might potentially apply to all schemas? Should this also or instead be documented at a higher level?