object<R>(schemaRecord): Schema<{ [k in keyof R]: Infer<R[k]> }>
The object schema checks that the type of the value is an object, and that all of its
properties match the given schemas. The properties are defined in a record. The keys of the
record are the property names, and the values are the schemas to validate the properties.
if (is(schema)({ name:"John", age:42 })) { console.log("value is an object with a name and an age"); } if (!is(schema)({ name:"John", age:"42" })) { console.log("value is not an object with a name and an age"); }
If you use the validate function, the errors contain all of the different type validation fails
from the object.
Objects can be combined with any other schemas, to create complex validation patterns.
The
object
schema checks that the type of the value is an object, and that all of its properties match the given schemas. The properties are defined in a record. The keys of the record are the property names, and the values are the schemas to validate the properties.Example
If you use the
validate
function, the errors contain all of the different type validation fails from the object.Objects can be combined with any other schemas, to create complex validation patterns.