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

Allow coercion when given union of coercible values #427

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sebinsua
Copy link

@sebinsua sebinsua commented Dec 12, 2023

A value is coercible if it itself is coercible or if it is a union of only coercible values.

This is somewhat related to #255 but only improves upon unions by avoiding the error and supporting coercions. It doesn't add support for discriminated unions, as according to the issue linked to, these lack upstream support within OpenAPI (???).

Note: I originally wrote some code to support intersections in the same way but I've removed this because I don't have a practical example of when it would make sense.

src/utils/zod.ts Outdated Show resolved Hide resolved
@sebinsua sebinsua changed the title Allow coercion when given union or intersection of coercible values Allow coercion when given union of coercible values Dec 12, 2023
@sebinsua sebinsua force-pushed the allow-union-or-intersection-coercion-when-possible branch from 2ff14b5 to 5af397a Compare December 12, 2023 17:08
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