Skip to content
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: add cast nullability migration path. #1749

Merged
merged 1 commit into from
Aug 19, 2022
Merged

feat: add cast nullability migration path. #1749

merged 1 commit into from
Aug 19, 2022

Conversation

jquense
Copy link
Owner

@jquense jquense commented Aug 19, 2022

Adds a cast option to not throw on optionality mismatches after casting. This is being added to support migration from pre-v1 where cases like string().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 for null or undefined 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 using schema.deepPartial() to create an optional version of itself.

@jquense jquense merged commit 2bb099e into master Aug 19, 2022
@jquense jquense deleted the migration-path branch August 19, 2022 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant