Sum type / oneOfType
See original GitHub issueHi 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 as oneOfType
. I think yup
would probably have either oneOfType
or .or
as in .string().or(yup.number())
.
Is anything like this supported?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:12
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Documentation - Advanced Types - TypeScript
This page lists some of the more advanced ways in which you can model types, it works in tandem with the Utility Types...
Read more >1 More types - Cornell CS
Intuitively, a product holds two values, one of type τ1, and one of type τ2. By contrast, a sum holds a single value...
Read more >3.9. Algebraic Data Types — OCaml Programming
The sum types come from the fact that a value of a variant is formed by one of the constructors. The product types...
Read more >Adding Either type to the Standard Library - #80 by filip-sakel
Until this thread, I never saw a sum-tuple idea with just a label for ... Nonetheless Varidadic Generics are required to make an...
Read more >Typed Compilation of Recursive Datatypes
The generativity of datatypes poses some challenges for type- directed compilation of SML. ... into one of type δ, and the latter is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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:
something like?