{"id":26546,"library":"typebox","title":"TypeBox","description":"TypeBox is a runtime type system that constructs JSON Schema objects from TypeScript-like type definitions, automatically inferring static TypeScript types via Type.Static. The current stable version is 1.1.36, with frequent releases following semantic versioning. It differentiates itself by providing a unified type system that works both at compile time (TypeScript type checking) and runtime (JSON Schema validation), making it ideal for API validation, data serialization, and building type-safe protocols. Unlike standalone validators like Ajv or Zod, TypeBox focuses exclusively on schema generation and type inference, leaving validation to JSON Schema validators.","status":"active","version":"1.1.36","language":"javascript","source_language":"en","source_url":"https://github.com/sinclairzx81/typebox","tags":["javascript","typescript","jsonschema"],"install":[{"cmd":"npm install typebox","lang":"bash","label":"npm"},{"cmd":"yarn add typebox","lang":"bash","label":"yarn"},{"cmd":"pnpm add typebox","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package exposes a default export. In CommonJS, require returns the default export directly, so you can use const Type = require('typebox'). Do not use destructuring { Type } as it won't work.","wrong":"const Type = require('typebox').default","symbol":"default (Type)","correct":"import Type from 'typebox'"},{"note":"Type.String is a function that returns a JSON Schema object. All type builders accept optional parameters for constraining the schema (e.g., format, minLength). Since typebox v1, all type definitions are function calls.","wrong":"Type.String({ format: 'email' })","symbol":"Type.String","correct":"Type.String({ format: 'email' })"},{"note":"Type.Static is a generic type that extracts the inferred TypeScript type from a schema. It must be used with typeof schema, not the schema value directly. This is a type-level operation, not a runtime function.","wrong":"type T = Type.Static<schema>","symbol":"Type.Static","correct":"type T = Type.Static<typeof schema>"}],"quickstart":{"code":"import Type from 'typebox';\n\nconst User = Type.Object({\n  id: Type.String(),\n  name: Type.String(),\n  email: Type.String({ format: 'email' }),\n  age: Type.Optional(Type.Number({ minimum: 0 }))\n});\n\ntype UserType = Type.Static<typeof User>;\n// equivalent to: { id: string; name: string; email: string; age?: number }\n\n// Validate with any JSON Schema validator (not included)\nconst Ajv = require('ajv');\nconst ajv = new Ajv();\nconst validate = ajv.compile(User);\nconst result = validate({ id: '1', name: 'Alice', email: 'alice@example.com' });\nconsole.log(result); // true","lang":"typescript","description":"Shows how to define an object schema with TypeBox, infer the TypeScript type using Type.Static, and validate data with Ajv."},"warnings":[{"fix":"Use Type.Static<typeof schema> as a type annotation, not a runtime value.","message":"Type.Static is a type, not a function. It can only be used in type positions, not runtime.","severity":"gotcha","affected_versions":">=0.1"},{"fix":"Always use parentheses: Type.String(), not Type.String.","message":"All type builders (e.g., Type.String()) must be called as functions, even without arguments.","severity":"gotcha","affected_versions":">=1.0"},{"fix":"Use Type.Object({ key: Type.String() }) instead of Type.Object({ key: { type: 'string' } }).","message":"Type.Object requires properties to be registered with Type.* builders, not plain objects.","severity":"gotcha","affected_versions":">=1.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Ensure you have the correct import: import Type from 'typebox'. If you see this in a type annotation, you might have a naming conflict.","cause":"Using Type before importing or using Type as a type instead of value.","error":"Cannot find name 'Type'. Did you mean the type 'Type'?"},{"fix":"Call Type.String() with parentheses, even if no arguments: Type.String().","cause":"Using Type.String (or other builders) as a property access without calling it as a function.","error":"TypeError: Type.String is not a function"},{"fix":"Ensure the argument to Type.Static is a schema built with TypeBox builders: Type.Static<typeof mySchema> where mySchema is constructed via Type.*.","cause":"Using Type.Static with a non-TypeBox schema object (e.g., a plain object literal).","error":"Type 'typeof schema' does not satisfy the constraint 'TBoxSchema'."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}