anystructs accept any value as valid.
arraystructs accept a list of values of a specific type.
bigintstructs validate that a value is a bigint.
booleanstructs accept the boolean values
datestructs do not accept invalid
Dateobjects, even though they are technically an instance of a
Date. This meshes with the 99% use case where invalid dates create inconsistencies.
enumsstructs validate that a value is one of a specific set of literals values.
funcstructs validate that a value is a function.
integerstructs validate that a value is an integer.
intersectionstructs validate that a value matches all of many structs. It takes existing struct objects as arguments.
literalstructs enforce that a value matches an exact value using the
mapstructs validate that a value is a
Mapobject with specific types for its keys and values.
mapit will traverse all the properties to ensure they are valid! If you don't care about validating the properties of the map, you can write
neverstructs will fail validation for every value.
numberstructs validate that a value is a number.
nullablestructs validate that a value matches a specific struct, or that it is
objectstructs validate that a value is an object and that each of its properties match a specific type as well.
optionalstructs validate that a value matches a specific struct, or that it is
recordstructs validate an object with specific types for its keys and values. But, unlike
objectstructs, they do not enforce a specific set of keys.
regexpstructs validate that a value is a
setstructs validate that a value is a
Setinstance with elements of a specific type.
setit will traverse all the children to ensure they are valid! If you don't care about validating the elements of the set, you can write
stringstructs validate that a value is a string.
tuplestructs validate that a value is an array of a specific length with values each of a specific type.
typestructs 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
typeas 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.
unionstructs validate that a value matches at least one of many types.
unknownstructs accept unknown value as valid without loosening its type to
true/falseor an array of
StructFailureobjects, in case you want to build more helpful error messages.
unknownby default. You can pass a more specific type for Typescript: