TypeBox

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

Library
npm
v0.34.52
10stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
31/100Needs Attention
Development Activity48
Maintenance16
Community12
Maturity28
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
78/100Good
Architecture80
Code Quality78
Innovation82
Learning Curve70

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

Marketing · Automation

2,903

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
63
Dependency
Built with
TypeScript92%
Updated 4 months ago
TypeScript
91%
MIT

GB Studio

Developer Tools · Game Development · Design Tools

9,372

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

View details
89
Repo Health
83
Technical
80
Dependency
Built with
TypeScript91%
Updated today
TypeScript
98%
MIT

GraphQL Hive

Developer Tools · Devops · Monitoring

485

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
70
Dependency
Built with
TypeScript98%
Updated today
TypeScript
76%
AGPL 3.0

massCode

Developer Tools · Productivity · Code Editors

6,959

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

View details
86
Repo Health
87
Technical
64
Dependency
Built with
TypeScript76%
Vue22%
Updated 2 days ago
TypeScript
93%
Apache 2.0

Openship

Devops · Hosting Control Panel

11,078

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
82
Repo Health
85
Technical
65
Dependency
Built with
TypeScript93%
Updated today
Python
74%
AGPL 3.0

OpenViking

Databases · AI Development

29,711

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

View details
84
Repo Health
75
Technical
65
Dependency
Built with
Python74%
Rust14%
Updated today
TypeScript
92%
Other

Hexclave

Developer Tools · Authentication

6,841

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

View details
88
Repo Health
80
Technical
67
Dependency
Built with
TypeScript92%
Updated today
TypeScript
99%
Apache 2.0

Trigger.dev

Automation · AI Development · Developer Tools

16,062

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
90
Repo Health
9
Technical
65
Dependency
Built with
TypeScript99%
Updated today
TypeScript
95%
MIT

understudy

AI Agents · Automation

457

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
45
Repo Health
79
Technical
74
Dependency
Built with
TypeScript95%
Updated 2 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

Search