Skip to main content
TypeBox is a TypeScript library where types are JSON Schema objects. No export step is needed; the schema you write is the schema you send.

Install

Basic usage

TypeBox types produce JSON Schema directly. Pass them to the Vercel AI SDK’s jsonSchema() 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

Notes

  • Pass { additionalProperties: false } as the second argument to Type.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.

Next steps