by noir

TypeBox is a runtime type system that builds JSON Schema objects with static TypeScript type inference, enabling unified validation at runtime and compile time.
TypeBox is a runtime type system that generates JSON Schema objects which simultaneously resolve as TypeScript static types. It is aimed at developers building validated APIs, RPC services, or any system requiring a single source of truth for both compile-time type safety and runtime data validation. The library has no runtime dependencies.
compile/ - JIT compilation of TypeBox schemas into fast validator functionserror/ - Structured error types and error iteration for validation failuresformat/ - String format validators (email, uuid, uri, date, etc.) with a registration registryguard/ - Type guard utilities for inspecting TypeBox schema nodes at runtimeschema/ - JSON Schema-level parsing, checking, and building from raw schema objectssystem/ - Runtime system configuration (custom types, error messages, formats)type/ - Core schema constructors (the Type.* builder API)value/ - Value-level operations: clone, check, convert, decode, default, diff, patchindex.ts - Main barrel export; re-exports everything and exports Type namespacetypebox.ts - Aggregated Type namespace used as the default export# TypeBox has no runtime npm dependencies.
# Install TypeScript tooling if not already present:
npm install --save-dev typescript tsx
No native modules, no pod install, no Android linking, no prebuild steps required.
Copy the source/ directory into your project, e.g. src/lib/typebox/.
In tsconfig.json, ensure at minimum:
{
"compilerOptions": {
"target": "ES2020",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"strict": true,
"paths": {
"typebox": ["./src/lib/typebox/index.ts"],
"typebox/*": ["./src/lib/typebox/*"]
}
}
}
If you use .ts extension imports (the source uses import './foo.ts'), set "allowImportingTsExtensions": true or run via tsx / ts-node --esm. Alternatively, do a search-replace on extensions in imports if you target CommonJS.
Spin up an isolated sandbox and run it server-side — no local setup.
Tetrees AI Review of this version
This TypeScript cli / script completed archive review. Structure, dependency manifests, documentation, functional source, and common risk patterns were checked by the Tetrees verification pipeline; runtime phases are stated separately.
Deterministic AVCP artifact review
Pipeline avcp-2026-08-04.1 · SHA-256 15f9f52a60c9454d…
This version-scoped review deterministically inspects the submitted archive for structure, dependencies, documentation, functional source, and common malicious or high-risk signals. Build and test phases are reported as passed only after an isolated sandbox audition. It is not a guarantee of perfect security.
Reviewed Aug 4, 2026
Push this product straight into your AI IDE, web builder or cloud IDE.
Connect Tetrees to a compatible AI IDE, list products you own, and request the verified ZIP without exposing seller upload controls.
No reviews yet.
Sign in to join the discussion
Loading discussion…
.tsImport from your alias:
import Type from 'typebox'
// or
import { Type } from './src/lib/typebox/index.ts'
import Type from 'typebox'
// or
import * as Type from './src/lib/typebox/typebox.ts'
const Schema = Type.Object({ name: Type.String(), age: Type.Number() })
type Schema = typeof Type.Static<typeof Schema>
The Type namespace is the primary entry point. Use Type.Object, Type.String, Type.Number, Type.Array, Type.Union, Type.Literal, Type.Optional, and many more to build schemas. Each call returns a plain JSON Schema object augmented with TypeScript inference metadata.
import { Compile } from './src/lib/typebox/compile/index.ts'
const validator = Compile(schema)
const ok: boolean = validator.Check(value)
const errors = [...validator.Errors(value)]
Compile JIT-compiles a TypeBox schema into a Validator instance with a .Check(value) method and an .Errors(value) iterator. Use this for hot-path validation where schema checking happens repeatedly and performance matters.
import { Validator } from './src/lib/typebox/compile/index.ts'
// Validator is the class returned by Compile(schema)
// validator.Check(value: unknown): boolean
// validator.Errors(value: unknown): IterableIterator<ValueError>
Validator wraps a compiled check function. Call .Check for a boolean result. Call .Errors to iterate detailed ValueError objects containing path, message, and schema for each failure. Use it in Express middleware, tRPC procedures, or any validation boundary.
import Format from './src/lib/typebox/format/index.ts'
// Format.Set(name: string, fn: (value: string) => boolean): void
// Format.Get(name: string): ((value: string) => boolean) | undefined
// Format.Has(name: string): boolean
The Format namespace provides a registry for string format validators. Call Format.Set to register a custom format (e.g. 'cuid') and then reference it with Type.String({ format: 'cuid' }). Validators created with Compile will invoke registered format functions at runtime.
Create a schema once, infer the TypeScript type from it, and use both together throughout your codebase.
import Type from './src/lib/typebox/index.ts'
const User = Type.Object({
id: Type.String({ format: 'uuid' }),
name: Type.String({ minLength: 1 }),
age: Type.Number({ minimum: 0 }),
role: Type.Union([Type.Literal('admin'), Type.Literal('user')])
})
// Infer the TypeScript type
type User = typeof User extends { static: infer T } ? T : never
const example: User = { id: 'abc', name: 'Alice', age: 30, role: 'admin' }
Validate incoming request bodies with a JIT-compiled validator, returning 400 with structured errors on failure.
import express from 'express'
import Type from './src/lib/typebox/index.ts'
import { Compile } from './src/lib/typebox/compile/index.ts'
const CreatePost = Type.Object({
title: Type.String({ minLength: 1, maxLength: 120 }),
content: Type.String({ minLength: 1 }),
tags: Type.Array(Type.String(), { maxItems: 10 })
})
const validator = Compile(CreatePost)
const app = express()
app.use(express.json())
app.post('/posts', (req, res) => {
if (!validator.Check(req.body)) {
const errors = [...validator.Errors(req.body)].map(e => ({
path: e.path,
message: e.message
}))
return res.status(400).json({ errors })
}
// req.body is valid here
res.status(201).json({ ok: true })
})
Add a cuid format to the registry and validate strings against it at runtime.
import Type from './src/lib/typebox/index.ts'
import Format from './src/lib/typebox/format/index.ts'
import { Compile } from './src/lib/typebox/compile/index.ts'
// Register the format before compiling schemas that use it
Format.Set('cuid', (value) => /^c[a-z0-9]{24}$/.test(value))
const IdSchema = Type.Object({
id: Type.String({ format: 'cuid' })
})
const validator = Compile(IdSchema)
console.log(validator.Check({ id: 'cjld2cjxh0000qzrmn831i7rn' })) // true
console.log(validator.Check({ id: 'not-a-cuid' })) // false
for (const err of validator.Errors({ id: 'bad' })) {
console.log(err.path, err.message)
}
index.ts - Top-level barrel: re-exports all sub-modules and the Type namespace as default.typebox.ts - Aggregates all Type.* builder functions into a single namespace object.compile/ - Contains Code (code generation), Compile (schema → validator), and Validator (compiled check/error interface).error/ - Defines ValueError and error iteration helpers used by validators to report validation failures.format/ - Built-in format implementations (date, email, uuid, uri, etc.) plus Format.Set/Get/Has registry API.guard/ - Runtime inspection guards: Guard for schema-node checks, EmitGuard, GlobalsGuard, NativeGuard for internal use.schema/ - Low-level JSON Schema engine: parsing raw schemas, building TypeBox schemas from plain JSON Schema, error resolution.system/ - Global runtime configuration such as registering custom types and overriding error messages.type/ - Core implementation of every Type.* constructor, including action, engine, extends, script, and types sub-modules.value/ - Functional utilities operating on values: Value.Check, Value.Clone, Value.Convert, Value.Default, Value.Diff, Value.Patch..ts extension imports fail in CommonJS bundlers - The source uses explicit .ts extensions in imports; use tsx, ts-node --esm, or strip extensions with a path alias in your bundler config.Format.Set(name, fn) before Compile is called; registration order matters.allowImportingTsExtensions required - Set "allowImportingTsExtensions": true in tsconfig.json when using tsc directly, or the compiler will reject .ts extension imports.Compile(schema) once at module load time and reuse the returned Validator; calling it per-request is wasteful.Static<T> type inference - To infer the TypeScript type from a schema, use import type { Static } from './src/lib/typebox/index.ts' then type T = Static<typeof MySchema>.default export - The default export is the Type namespace object; with esModuleInterop: true use import Type from 'typebox', otherwise use import * as Type from 'typebox'.I have a TypeBox source library copied into `src/lib/typebox/` in my project.
There is a USAGE.md file at the root describing the full API, file structure,
and working examples.
Please help me integrate TypeBox into my project step by step:
1. Read USAGE.md and the files under `src/lib/typebox/` to understand the API.
2. The main entry point is `src/lib/typebox/index.ts`, which exports the `Type`
namespace as default and all sub-modules as named exports.
3. For compiled validation, import `Compile` from `src/lib/typebox/compile/index.ts`.
4. For custom string formats, import the `Format` default from `src/lib/typebox/format/index.ts`.
5. My project uses [TypeScript / Express / Node.js - replace as needed].
6. Please create:
- A schema file using `Type.Object`, `Type.String`, `Type.Number`, etc.
- A compiled validator using `Compile(schema)` with `.Check()` and `.Errors()`.
- Middleware or a service function that validates incoming data against the schema.
7. Make sure all imports reference the real files in `src/lib/typebox/` and
match the exports shown in USAGE.md.
8. Do not install the `typebox` npm package; use the local source directly.
TypeBox is released under the MIT License. Copyright (c) 2017-2026 Haydn Paterson. See source/ file headers for the full license text. Upstream project: sinclairzx81/typebox.
This product’s unique contribution is clean room implementation of valuable code block into AVCP compatible standard.
The full install guide and integration prompts unlock after purchase.
Automation, Utilities & Developer Tools
Free