Status: implemented
array(t) admits an array of any length whose every element is a t. record(t) admits an object with any string keys, each holding a t.
const tags = array(string) // readonly string[]
const stock = record(number) // { readonly [k in string]?: number }
Both are homogeneous. An array whose positions differ is a tuple, and an object with known keys is a struct; rest combines the two, declared members and then any number of members of one schema. array(or()) admits only the empty array, an empty rest bounding the length.
The demo on this page runs the Dictionary lesson: record(number) against {"apples":3,"pears":5}, with its graph, its TypeScript type, its JSON Schema, and what parse and validate make of the value. Change a count to a string to see both refuse it. The lesson is defined in sample.f.mjs, and the module page's demo lists it among all the others.
- TypeScript: arrays and index signatures
- JSON Schema:
itemsandadditionalProperties(array, object)
The unary schemas in module.f.mjs; the container skeletons in common.