constschema = either(value("hello"), value(42), boolean); if (is(schema)("hello")) { console.log("value matches one of the types"); } if (is(schema)(42)) { console.log("value matches one of the types"); } if (is(schema)(true)) { console.log("value matches one of the types"); } if (!is(schema)(undefined)) { console.log("value does not match any of the types"); }
If you use the validate function, the errors contain all of the different type validation fails
from the union.
The
either
schema is the equivalent of the TypeScript union (|
). It allows you to validate that a value is of any type between a set of options.Example
If you use the
validate
function, the errors contain all of the different type validation fails from the union.