Files
typebox/docs/overview.md

1.4 KiB

Overview

TypeBox

Json Schema Type Builder with Static Type Resolution for TypeScript



License

Example

import { Type, type Static } from "@alkdev/typebox";

const T = Type.Object({
  // const T = {
  x: Type.Number(), //   type: 'object',
  y: Type.Number(), //   required: ['x', 'y', 'z'],
  z: Type.Number(), //   properties: {
}); //     x: { type: 'number' },
//     y: { type: 'number' },
//     z: { type: 'number' }
//   }
// }

type T = Static<typeof T>; // type T = {
//   x: number,
//   y: number,
//   z: number
// }

Overview

TypeBox is a runtime type builder that creates in-memory Json Schema objects that infer as TypeScript types. The schematics produced by this library are designed to match the static type checking rules of the TypeScript compiler. TypeBox offers a unified type that can be statically checked by TypeScript and runtime asserted using standard Json Schema validation.

This library is designed to allow Json Schema to compose similar to how types compose within TypeScript's type system. It can be used as a simple tool to build up complex schematics or integrated into REST and RPC services to help validate data received over the wire.

License MIT


Back to Home