TypeBox

JSON Schema type builder with static TypeScript type inference and zero dependencies.

Library
npm
v0.34.52
12 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
28 /100 Needs Attention
Development Activity 32
Maintenance 16
Community 12
Maturity 32
Momentum 20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
78 /100 Good
Architecture 80
Code Quality 78
Innovation 82
Learning Curve 70

TypeBox lets you define a single schema with a fluent builder API and get both a runtime Json Schema object and a fully inferred static TypeScript type from it. Instead of hand-writing a TypeScript interface and a matching Json Schema (or Zod/Ajv schema) separately, you write one TypeBox definition and derive both, keeping validation rules and types permanently in sync.

Beyond the type builder, the package ships a full value toolkit (Check, Cast, Convert, Clean, Default, Clone, Diff, Patch, Hash, Encode/Decode, Parse) and an optional TypeCompiler that JIT-compiles schemas into fast standalone validation functions, plus first-class interoperability with Ajv for teams that prefer a general-purpose Json Schema validator. It targets the Json Schema Draft 7 specification and has zero runtime dependencies.

What You Get

  • A fluent Type.* builder covering Json types (Object, Array, String, Number, Union, Literal) and JavaScript-native types (Date, Uint8Array, Promise, Map, Set)
  • Static<T> to derive a TypeScript type directly from any TypeBox schema, eliminating duplicate type declarations
  • A Value namespace with Check, Cast, Convert, Clean, Default, Clone, Diff, Patch, Hash, Encode/Decode, and Parse operators for working with runtime values against a schema
  • An optional TypeCompiler that JIT-compiles a schema into a standalone validation function, plus direct Ajv interoperability for teams standardizing on Ajv
  • TypeRegistry and FormatRegistry for registering custom types and string formats
  • Support for advanced TypeScript-mirroring composition: generics, recursive types, template literal types, mapped/indexed types, and conditional types

Common Use Cases

  • Validating request/response bodies in REST or RPC services without maintaining separate DTO types and validators
  • Generating OpenAPI/Json Schema documents directly from the same schema used for runtime validation
  • Parsing and coercing untrusted JSON (env vars, config files, webhook payloads) into typed, validated values
  • Sharing a single schema definition between a TypeScript backend and a Json Schema-based API contract

Under The Hood

Architecture — TypeBox is organized around a src/type tree (one directory per Json/JavaScript type — object, array, union, mapped, recursive, template-literal, etc.) that each export a Type.* builder function returning a plain, symbol-tagged schema object (Kind from src/type/symbols), and a parallel src/value tree implementing the Check/Cast/Convert/Clean/Default/Clone/Diff/Patch/Hash/Encode/Decode/Parse operators that walk those schema objects against runtime values. src/compiler/compiler.ts implements TypeCompiler, which walks a schema once and emits a JIT-compiled standalone validation function, pulling in TransformEncode/TransformDecode from value/transform, Errors/ValueErrorIterator from src/errors, and TypeRegistry/FormatRegistry from src/type/registry for extensibility. src/index.ts re-exports the full public surface as flat namespaces (Infrastructure, Types, Values, Syntax) rather than a single monolithic object, letting consumers subpath-import @sinclair/typebox/value or @sinclair/typebox/compiler independently.

Tech Stack — Pure TypeScript targeting the Json Schema Draft 7 specification, with zero runtime dependencies declared in package.json; devDependencies are limited to its own build tool (@sinclair/hammer), ajv/ajv-formats for cross-validator interop tests, mocha for the test runner, prettier for formatting, and @arethetypeswrong/cli for package-export correctness checks. The custom hammer task runner drives build/test/format/publish scripts in place of a conventional bundler config.

Code Quality — The test suite is split into test/runtime (functional behavior, ~570 describe blocks across type, value, compiler, compiler-ajv, errors, syntax, and system suites) and test/static (TypeScript type-level assertions), giving both runtime-correctness and type-inference coverage — a distinction few validation libraries make explicit. Source files consistently carry MIT license headers and are organized one-concept-per-file under deeply nested but predictably named directories (e.g. type/object/object.ts), which keeps individual files small despite the library’s large overall surface (~25k lines across src).

API Design — The builder API composes the way TypeScript’s own type system does (Type.Object({...}), Type.Union([...]), Type.Optional(...)), so the learning curve for anyone fluent in TypeScript types is shallow; Static<typeof T> is the single mechanism for going from schema to type, avoiding two-step decorator or codegen workflows. The tradeoff is a very large type-level implementation (heavy use of nested mapped/conditional types, visible in files like type/object/object.ts) needed to make that inference precise, which can produce dense compiler errors on advanced generic/recursive schemas.

Used by 9 apps in this directory

TypeScript
92%
MIT

Dittofeed

Automation · Marketing

2,968

Open-source omni-channel customer engagement platform for automating transactional and marketing messages via email, SMS, WhatsApp, Slack, and mobile push.

View details
54
Repo Health
75
Technical
62
Dependency
Built with
TypeScript 92%
Updated 6 months ago
TypeScript
92%
MIT

GB Studio

Design Tools · Developer Tools · Game Development

9,407

Drag-and-drop retro Game Boy game creator that compiles real ROMs — no coding required.

View details
88
Repo Health
83
Technical
73
Dependency
Built with
TypeScript 92%
Updated 1 weeks ago
TypeScript
99%
MIT

GraphQL Hive

Developer Tools · Devops · Monitoring

484

Open-source GraphQL schema registry and observability platform with breaking change detection, federation support, and CI/CD integration for teams of any size.

View details
90
Repo Health
81
Technical
69
Dependency
Built with
TypeScript 99%
Updated 4 days ago
TypeScript
80%
AGPL 3.0

massCode

Code Editors · Developer Tools · Productivity

7,003

A free, local-first developer workspace unifying snippets, notes, HTTP requests, calculations, drawings, and dev tools in one desktop app.

View details
87
Repo Health
87
Technical
63
Dependency
Built with
TypeScript 80%
Vue 19%
Updated 5 days ago
TypeScript
94%
Apache 2.0

Openship

Devops · Hosting Control Panel

12,979

Openship is an open-source, self-hostable deployment platform that points at a repo and builds, ships, routes, and TLS-terminates the app — driven from a desktop app, web dashboard, or CLI.

View details
84
Repo Health
85
Technical
65
Dependency
Built with
TypeScript 94%
Updated 5 days ago
Python
75%
AGPL 3.0

OpenViking

AI Development · AI Memory · Databases

38,819

An open-source context database that gives AI agents a unified filesystem for memory, resources, and skills with hierarchical tiered retrieval.

View details
85
Repo Health
75
Technical
64
Dependency
Built with
Python 75%
Rust 12%
Updated 4 days ago
TypeScript
89%
Other

Hexclave

Authentication · Developer Tools

6,862

The open-source user infrastructure platform — authentication, teams, payments, emails, analytics, and more on a single unified user model.

View details
87
Repo Health
80
Technical
66
Dependency
Built with
TypeScript 89%
Updated 6 days ago
TypeScript
99%
Apache 2.0

Trigger.dev

AI Development · Automation · Developer Tools

16,427

Build and deploy fully-managed AI agents and background jobs in TypeScript — with no timeouts, durable retries, real-time observability, and elastic scaling built in.

View details
89
Repo Health
9
Technical
63
Dependency
Built with
TypeScript 99%
Updated 1 weeks ago
TypeScript
95%
MIT

understudy

AI Agents · Automation

459

Open-source local AI agent that operates your entire computer — GUI, browser, shell, and messaging — from a single instruction, using your own models.

View details
33
Repo Health
79
Technical
73
Dependency
Built with
TypeScript 95%
Updated 3 months ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers