Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant