struct
factory.any
any
structs accept any value as valid.🤖 Note that if you're using TypeScript, theany
struct will loosen the type toany
, and you might want to useunknown
instead.
array
array
structs accept a list of values of a specific type.bigint
bigint
structs validate that a value is a bigint.boolean
boolean
structs accept the boolean values true
and false
.date
date
structs accept JavaScript Date
instances.🤖 To avoid unexpected runtime errors,date
structs do not accept invalidDate
objects, even though they are technically an instance of aDate
. This meshes with the 99% use case where invalid dates create inconsistencies.
enums
enums
structs validate that a value is one of a specific set of literals values.func
func
structs validate that a value is a function.instance
instance
structs validate that a value is an instance of a particular class, using JavaScript's built-in instanceof
operator.integer
integer
structs validate that a value is an integer.intersection
intersection
structs validate that a value matches all of many structs. It takes existing struct objects as arguments.literal
literal
structs enforce that a value matches an exact value using the ===
operator.map
map
structs validate that a value is a Map
object with specific types for its keys and values.🤖 When defining a key/value schemas withmap
it will traverse all the properties to ensure they are valid! If you don't care about validating the properties of the map, you can writemap()
instead.
never
never
structs will fail validation for every value.number
number
structs validate that a value is a number.nullable
nullable
structs validate that a value matches a specific struct, or that it is null
.object
object
structs validate that a value is an object and that each of its properties match a specific type as well.optional
optional
structs validate that a value matches a specific struct, or that it is undefined
.record
record
structs validate an object with specific types for its keys and values. But, unlike object
structs, they do not enforce a specific set of keys.regexp
regexp
structs validate that a value is a RegExp
object.🤖 This does not test the value against the regular expression! For that you want thepattern
refinement.
set
set
structs validate that a value is a Set
instance with elements of a specific type.🤖 When defining a child schema withset
it will traverse all the children to ensure they are valid! If you don't care about validating the elements of the set, you can writeset()
instead.
string
string
structs validate that a value is a string.tuple
tuple
structs validate that a value is an array of a specific length with values each of a specific type.type
type
structs validate that a value has a set of properties on it, but it does not assert anything about unspecified properties. This allows you to assert that a particular set of functionality exists without a strict equality check for properties.mask()
is used with a value of type
, its unknown properties are not removed. I.e. consider type
as a signal to the core that the object may have arbitrary properties in addition to the known ones, in both masked and non-masked validation.union
union
structs validate that a value matches at least one of many types.unknown
unknown
structs accept unknown value as valid without loosening its type to any
.true/false
or an array of StructFailure
objects, in case you want to build more helpful error messages.🤖 If you are using Typescript the value will be of typeunknown
by default. You can pass a more specific type for Typescript:1const Email = define<string>('Email', isEmail)Copied!