constschema = array(string); if (is(schema)(["hello", "world"])) { console.log("value is an array of strings"); } if (!is(schema)(["hello", 42])) { console.log("value is not an array of strings"); }
If you use the validate function, the errors contain all of the different type validation fails
from the array.
Arrays can be combined with any other schemas, to create complex validation patterns.
import { array, string, number } from"typerun/schema";
constschema = array(either(string, array(number))); if (is(schema)(["hello", [42, 31]])) { console.log("value is an array of strings and arrays of numbers"); }
The
array
schema checks that the type of the value is an array, and that all of its elements match the given schema.Example
If you use the
validate
function, the errors contain all of the different type validation fails from the array.Arrays can be combined with any other schemas, to create complex validation patterns.