Install
Basic usage
TypeBox types produce JSON Schema directly. Pass them to the Vercel AI SDK’sjsonSchema() wrapper to use with dottxt:
Adding constraints
TypeBox methods map directly to JSON Schema keywords:Optional and nullable fields
Type.Optional() removes the field from required. Type.Union([Type.String(), Type.Null()]) allows null.
Arrays
Nested objects
Type mapping
| TypeBox | JSON Schema | TypeScript |
|---|---|---|
Type.String() | {"type": "string"} | string |
Type.Number() | {"type": "number"} | number |
Type.Integer() | {"type": "integer"} | number |
Type.Boolean() | {"type": "boolean"} | boolean |
Type.Null() | {"type": "null"} | null |
Type.Array(T) | {"type": "array", "items": T} | T[] |
Type.Literal("x") | {"const": "x"} | "x" |
Type.Union([A, B]) | {"anyOf": [A, B]} | A | B |
Type.Optional(T) | removes from required | T | undefined |
Type.Object({...}) | {"type": "object", ...} | {...} |
Notes
- Pass
{ additionalProperties: false }as the second argument toType.Object()when you want strict object schemas. TypeBox does not set this by default, so omit it only when you intentionally want an open object. - TypeBox types are plain objects, so
JSON.stringify(Contact)gives you the JSON Schema directly. Static<typeof Schema>extracts the TypeScript type from a TypeBox schema, giving you type safety on both ends.