Getting Started
Last updated
<script src="https://unpkg.com/superstruct/lib/index.cjs"></script>const data = {
id: 42,
name: 'Jane Smith',
email: 'jane@example.com',
}import { object, number, string } from 'superstruct'
const User = object({
id: number(),
name: string(),
email: string(),
})import { assert } from 'superstruct'
assert(data, User)const data = {
id: 43,
name: false,
email: 'jane@example.com',
}
assert(data, User)
// StructError: 'Expected a value of type "string" for `name` but received `false`.' {
// type: 'string',
// value: false,
// branch: [{ ... }, false],
// path: ['name'],
// failures: [...],
// }