Skip to content

feat: add cast nullability migration path.#1749

Merged
jquense merged 1 commit intomasterfrom
migration-path
Aug 19, 2022
Merged

feat: add cast nullability migration path.#1749
jquense merged 1 commit intomasterfrom
migration-path

Conversation

@jquense
Copy link
Copy Markdown
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.

1 participant