typebox
$
npx mdskill add EpicenterHQ/epicenter/typeboxEnables runtime schema validation and JSON Schema generation using TypeBox and TypeMap
- Validates data structures at runtime using TypeBox schemas
- Leverages TypeBox and TypeMap for schema definition and conversion
- Compiles schemas for high-performance validation or one-off checks
- Generates Standard Schema interfaces for interoperability
SKILL.md
.github/skills/typeboxView on GitHub ↗
---
name: typebox
description: TypeBox and TypeMap patterns for runtime schema validation and JSON Schema generation. Use when mentioning TypeBox, TypeMap, Standard Schema, or schema-based validation.
metadata:
author: epicenter
version: '1.0'
---
# TypeBox and TypeMap
## Package Names
**Use `typebox`, not `@sinclair/typebox`**. The `@sinclair/typebox` package is deprecated.
```typescript
// Correct
import { Type } from 'typebox';
import { Compile } from 'typebox/compile';
import { Value } from 'typebox/value';
// Wrong - deprecated
import { Type } from '@sinclair/typebox';
```
## When to Use What
| Need | Use |
| ----------------------------- | -------------------------- |
| Define schemas | `typebox` with `Type.*` |
| Standard Schema support | `@sinclair/typemap` |
| Translate between libraries | `@sinclair/typemap` |
| High-performance validation | `Compile()` from either |
| One-off validation | `Value.Check()` from typebox |
## TypeMap for Standard Schema
TypeBox doesn't implement Standard Schema natively. Use TypeMap:
```typescript
import { Compile } from '@sinclair/typemap';
import { Type } from 'typebox';
// From TypeBox schema
const validator = Compile(
Type.Object({
name: Type.String(),
age: Type.Number(),
}),
);
// Standard Schema interface
const result = validator['~standard'].validate({ name: 'Alice', age: 30 });
```
## TypeMap Accepts Everything
`Compile()` from TypeMap accepts:
```typescript
import { Compile } from '@sinclair/typemap';
// TypeScript syntax strings
const v1 = Compile(`{ name: string, age: number }`);
// TypeBox schemas
const v2 = Compile(Type.Object({ x: Type.Number() }));
// Zod schemas
const v3 = Compile(z.object({ x: z.number() }));
// Valibot schemas
const v4 = Compile(v.object({ x: v.number() }));
```
All return validators with `['~standard'].validate()`.
## TypeBox Compile vs TypeMap Compile
```typescript
// TypeBox Compile - returns Validator with Check/Parse
import { Compile } from 'typebox/compile';
const validator = Compile(schema);
validator.Check(value); // boolean
validator.Parse(value); // throws or returns typed value
// TypeMap Compile - returns Standard Schema validator
import { Compile } from '@sinclair/typemap';
const validator = Compile(schema);
validator['~standard'].validate(value); // { value } or { issues }
```
Use TypeMap when you need Standard Schema compatibility. Use TypeBox directly when you don't.
## Translation Functions
TypeMap translates between libraries:
```typescript
import { Syntax, TypeBox, Zod, Valibot } from '@sinclair/typemap';
const syntax = `{ name: string }`;
const tbSchema = TypeBox(syntax);
const zodSchema = Zod(syntax);
const valibotSchema = Valibot(syntax);
const backToSyntax = Syntax(zodSchema);
```
## Performance
TypeMap's compiled validators are ~100x faster than native Zod:
| Library | 10M iterations |
| -------------- | -------------- |
| Zod native | ~4,669ms |
| TypeMap | ~47ms |
## References
- [TypeMap is the Real Deal](../../docs/articles/typemap-is-the-real-deal.md)
- [TypeBox is a Beast](../../docs/articles/typebox-is-a-beast.md)
- [Why TypeBox Won't Implement Standard Schema](../../docs/articles/typebox-standard-schema-criticisms.md)
More from EpicenterHQ/epicenter
- agent-goalWrite `/goal` prompts for long-running agent work in Codex or Claude Code. Use for slash goal, agent goal, durable objective, autonomous coding run.
- approachability-auditReview code as a new TypeScript developer. Use when code feels indirect, clever, hard to follow, or needs a pass on abstractions, names, first-read clarity.
- arktypeArktype: runtime validation, discriminated unions with .merge()/.or(), spread keys. Use when mentioning arktype, type(), union types, command/event schemas.
- attach-primitiveContract and invariants for `attach*` composition primitives in `packages/workspace` (side-effectful building blocks like attachIndexedDb, attachSqlite, attachBroadcastChannel, attachEncryption, attachTable, openCollaboration), and when to use `create*` (pure construction) instead. Use when writing or reviewing an `attach*` or `create*` function, naming a new workspace primitive, composing inside a workspace builder, or deciding whether a primitive registers listeners at call time.
- authEpicenter auth packages: `@epicenter/auth`, `@epicenter/auth-svelte`, OAuth sessions, identity state, auth-owned fetch/WebSocket, and workspace lifecycle binding. Use when editing Epicenter auth clients, session state, hosted sign-in, or auth/workspace integration.
- autumnAutumn billing in Epicenter: `autumn.config.ts`, `autumn-js` credit checks, `atmn` CLI, plan gates, and metered AI usage. Use when changing billing, pricing, credits, plan access, refunds, or usage events.
- better-auth-best-practicesBetter Auth server/client setup: `auth.ts`, generated schema, DB adapters, sessions, cookies, env vars, and plugins. Use when mentioning Better Auth, betterauth, auth handlers, OAuth, email/password, or session configuration.
- better-auth-security-best-practicesBetter Auth security hardening: rate limits, secrets, CSRF, trusted origins, cookies, sessions, OAuth tokens, and audit logging. Use when reviewing auth security, brute-force protection, token handling, or deployment safety.
- change-proposalPresent proposed code changes visually before implementing. Use when: "show me options", "compare approaches", "what should we do", or when changes need before/after comparison.
- claude-code-consultUse this skill when the user asks to consult Claude, ask Claude Code, get another model's take, run a taste check, find cleaner options, or prepare a Claude prompt. Create a bounded second-opinion prompt or run a read-only Claude Code consult, then verify Claude's claims against local files.