feat: add cast nullability migration path. #1749
Merged
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.
Adds a
cast
option to not throw on optionality mismatches after casting. This is being added to support migration from pre-v1 where cases likestring().nullable().required()
are supported. This case is generally used to handle parsing server side "default" values to feed into a form. Initial values may be null or missing but require filling in by a user before submitting the value back to server.cast(value, { assert: 'ignore-optionality'})
will only throw if the cast value doesn't match the strict type, but will pass fornull
orundefined
values. The returned TS type will also be optional even if the current config would create a present type, just to be safe.Going forward the approved way to handle these cases is with multiple schema using conditional when's to set
nullable
or usingschema.deepPartial()
to create an optional version of itself.