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
Sum type / oneOfType #321
Comments
It looks like Joi has this as |
we don't have anything like |
@jquense Could you please provide a basic example? |
something like? const schema = yup.lazy(value => typeof value === 'number' yup.number() : yup.string()) |
Using |
@rivertam @Aaronius @sublimeye I hit against this issue as well (among others) so I made a validation library that supports it: https://github.com/vriad/zod Specifically, there is a built-in "union" type, like so: const numOrString = z.union([ z.string(), z.number() ]) |
Hi there. Sorry if this is already included, but I can't find any documentation or issues regarding it.
I'm looking for a way to validate that a given type is one of multiple possible types. In FP, it would look like
number | string
, for example. React PropTypes offers this asoneOfType
. I thinkyup
would probably have eitheroneOfType
or.or
as in.string().or(yup.number())
.Is anything like this supported?
The text was updated successfully, but these errors were encountered: