1 line
212 KiB
JSON
1 line
212 KiB
JSON
{"success":true,"data":{"web":[{"url":"https://github.com/sinclairzx81/typebox","title":"sinclairzx81/typebox: JSON Schema Type Builder with ... - GitHub","description":"TypeBox offers a unified type system that can be statically checked by TypeScript and validated at runtime using standard JSON Schema. This library is designed ...","position":1,"category":"github","markdown":"[Skip to content](https://github.com/sinclairzx81/typebox#start-of-content)\n\nYou signed in with another tab or window. [Reload](https://github.com/sinclairzx81/typebox) to refresh your session.You signed out in another tab or window. [Reload](https://github.com/sinclairzx81/typebox) to refresh your session.You switched accounts on another tab or window. [Reload](https://github.com/sinclairzx81/typebox) to refresh your session.Dismiss alert\n\n{{ message }}\n\n[sinclairzx81](https://github.com/sinclairzx81)/ **[typebox](https://github.com/sinclairzx81/typebox)** Public\n\n- [Notifications](https://github.com/login?return_to=%2Fsinclairzx81%2Ftypebox) You must be signed in to change notification settings\n- [Fork\\\\\n197](https://github.com/login?return_to=%2Fsinclairzx81%2Ftypebox)\n- [Star\\\\\n6.6k](https://github.com/login?return_to=%2Fsinclairzx81%2Ftypebox)\n\n\nmain\n\n[**13** Branches](https://github.com/sinclairzx81/typebox/branches) [**380** Tags](https://github.com/sinclairzx81/typebox/tags)\n\n[Go to Branches page](https://github.com/sinclairzx81/typebox/branches)[Go to Tags page](https://github.com/sinclairzx81/typebox/tags)\n\nGo to file\n\nCode\n\nOpen more actions menu\n\n## Folders and files\n\n| Name | Name | Last commit message | Last commit date |\n| --- | --- | --- | --- |\n| ## Latest commit<br>[](https://github.com/sinclairzx81)[sinclairzx81](https://github.com/sinclairzx81/typebox/commits?author=sinclairzx81)<br>[Version 1.1.9 (](https://github.com/sinclairzx81/typebox/commit/686b9a29b34901edaf50fac00c523db5c1229878) [#1551](https://github.com/sinclairzx81/typebox/pull/1551) [)](https://github.com/sinclairzx81/typebox/commit/686b9a29b34901edaf50fac00c523db5c1229878)<br>Open commit detailssuccess<br>1 hour agoMar 29, 2026<br>[686b9a2](https://github.com/sinclairzx81/typebox/commit/686b9a29b34901edaf50fac00c523db5c1229878) · 1 hour agoMar 29, 2026<br>## History<br>[735 Commits](https://github.com/sinclairzx81/typebox/commits/main/) <br>Open commit details<br>[View commit history for this file.](https://github.com/sinclairzx81/typebox/commits/main/) 735 Commits |\n| [.github](https://github.com/sinclairzx81/typebox/tree/main/.github \".github\") | [.github](https://github.com/sinclairzx81/typebox/tree/main/.github \".github\") | [Maintenance (](https://github.com/sinclairzx81/typebox/commit/672ff3ffb88088bf0c5b94a7ae5d792e27296f9e \"Maintenance (#1528) * Add TypeScript Native Build Task * TypeScript Native Nightly Build\") [#1528](https://github.com/sinclairzx81/typebox/pull/1528) [)](https://github.com/sinclairzx81/typebox/commit/672ff3ffb88088bf0c5b94a7ae5d792e27296f9e \"Maintenance (#1528) * Add TypeScript Native Build Task * TypeScript Native Nightly Build\") | last monthFeb 2, 2026 |\n| [.vscode](https://github.com/sinclairzx81/typebox/tree/main/.vscode \".vscode\") | [.vscode](https://github.com/sinclairzx81/typebox/tree/main/.vscode \".vscode\") | [Version 1.0.0](https://github.com/sinclairzx81/typebox/commit/874c75ef241dd005e795b2080cb41dfca9cafd5e \"Version 1.0.0\") | 6 months agoSep 15, 2025 |\n| [changelog](https://github.com/sinclairzx81/typebox/tree/main/changelog \"changelog\") | [changelog](https://github.com/sinclairzx81/typebox/tree/main/changelog \"changelog\") | [Version 1.1.9 (](https://github.com/sinclairzx81/typebox/commit/686b9a29b34901edaf50fac00c523db5c1229878 \"Version 1.1.9 (#1551) * Positional Distributive Types * ChangeLog * Version * Comments\") [#1551](https://github.com/sinclairzx81/typebox/pull/1551) [)](https://github.com/sinclairzx81/typebox/commit/686b9a29b34901edaf50fac00c523db5c1229878 \"Version 1.1.9 (#1551) * Positional Distributive Types * ChangeLog * Version * Comments\") | 1 hour agoMar 29, 2026 |\n| [design](https://github.com/sinclairzx81/typebox/tree/main/design \"design\") | [design](https://github.com/sinclairzx81/typebox/tree/main/design \"design\") | [Documentation](https://github.com/sinclairzx81/typebox/commit/fda01b4402bf94c7dbe12a73bdb960fe47a14754 \"Documentation\") | yesterdayMar 28, 2026 |\n| [docs](https://github.com/sinclairzx81/typebox/tree/main/docs \"docs\") | [docs](https://github.com/sinclairzx81/typebox/tree/main/docs \"docs\") | [Documentation](https://github.com/sinclairzx81/typebox/commit/fda01b4402bf94c7dbe12a73bdb960fe47a14754 \"Documentation\") | yesterdayMar 28, 2026 |\n| [example](https://github.com/sinclairzx81/typebox/tree/main/example \"example\") | [example](https://github.com/sinclairzx81/typebox/tree/main/example \"example\") | [Documentation](https://github.com/sinclairzx81/typebox/commit/f9d0cb5f4632f1c0311454327149026cde8b3c39 \"Documentation\") | last weekMar 23, 2026 |\n| [src](https://github.com/sinclairzx81/typebox/tree/main/src \"src\") | [src](https://github.com/sinclairzx81/typebox/tree/main/src \"src\") | [Version 1.1.9 (](https://github.com/sinclairzx81/typebox/commit/686b9a29b34901edaf50fac00c523db5c1229878 \"Version 1.1.9 (#1551) * Positional Distributive Types * ChangeLog * Version * Comments\") [#1551](https://github.com/sinclairzx81/typebox/pull/1551) [)](https://github.com/sinclairzx81/typebox/commit/686b9a29b34901edaf50fac00c523db5c1229878 \"Version 1.1.9 (#1551) * Positional Distributive Types * ChangeLog * Version * Comments\") | 1 hour agoMar 29, 2026 |\n| [task](https://github.com/sinclairzx81/typebox/tree/main/task \"task\") | [task](https://github.com/sinclairzx81/typebox/tree/main/task \"task\") | [Version 1.1.9 (](https://github.com/sinclairzx81/typebox/commit/686b9a29b34901edaf50fac00c523db5c1229878 \"Version 1.1.9 (#1551) * Positional Distributive Types * ChangeLog * Version * Comments\") [#1551](https://github.com/sinclairzx81/typebox/pull/1551) [)](https://github.com/sinclairzx81/typebox/commit/686b9a29b34901edaf50fac00c523db5c1229878 \"Version 1.1.9 (#1551) * Positional Distributive Types * ChangeLog * Version * Comments\") | 1 hour agoMar 29, 2026 |\n| [test](https://github.com/sinclairzx81/typebox/tree/main/test \"test\") | [test](https://github.com/sinclairzx81/typebox/tree/main/test \"test\") | [Version 1.1.9 (](https://github.com/sinclairzx81/typebox/commit/686b9a29b34901edaf50fac00c523db5c1229878 \"Version 1.1.9 (#1551) * Positional Distributive Types * ChangeLog * Version * Comments\") [#1551](https://github.com/sinclairzx81/typebox/pull/1551) [)](https://github.com/sinclairzx81/typebox/commit/686b9a29b34901edaf50fac00c523db5c1229878 \"Version 1.1.9 (#1551) * Positional Distributive Types * ChangeLog * Version * Comments\") | 1 hour agoMar 29, 2026 |\n| [.gitignore](https://github.com/sinclairzx81/typebox/blob/main/.gitignore \".gitignore\") | [.gitignore](https://github.com/sinclairzx81/typebox/blob/main/.gitignore \".gitignore\") | [Version 1.0.0](https://github.com/sinclairzx81/typebox/commit/874c75ef241dd005e795b2080cb41dfca9cafd5e \"Version 1.0.0\") | 6 months agoSep 15, 2025 |\n| [deno.jsonc](https://github.com/sinclairzx81/typebox/blob/main/deno.jsonc \"deno.jsonc\") | [deno.jsonc](https://github.com/sinclairzx81/typebox/blob/main/deno.jsonc \"deno.jsonc\") | [Revision 1.1.7 (](https://github.com/sinclairzx81/typebox/commit/966a1b4f205405d86ebcfb7d320dcfe7290adf67 \"Revision 1.1.7 (#1549) * ParseBox 0.11.3 * ChangeLog * Version\") [#1549](https://github.com/sinclairzx81/typebox/pull/1549) [)](https://github.com/sinclairzx81/typebox/commit/966a1b4f205405d86ebcfb7d320dcfe7290adf67 \"Revision 1.1.7 (#1549) * ParseBox 0.11.3 * ChangeLog * Version\") | 2 days agoMar 27, 2026 |\n| [deno.lock](https://github.com/sinclairzx81/typebox/blob/main/deno.lock \"deno.lock\") | [deno.lock](https://github.com/sinclairzx81/typebox/blob/main/deno.lock \"deno.lock\") | [Revision 1.1.7 (](https://github.com/sinclairzx81/typebox/commit/966a1b4f205405d86ebcfb7d320dcfe7290adf67 \"Revision 1.1.7 (#1549) * ParseBox 0.11.3 * ChangeLog * Version\") [#1549](https://github.com/sinclairzx81/typebox/pull/1549) [)](https://github.com/sinclairzx81/typebox/commit/966a1b4f205405d86ebcfb7d320dcfe7290adf67 \"Revision 1.1.7 (#1549) * ParseBox 0.11.3 * ChangeLog * Version\") | 2 days agoMar 27, 2026 |\n| [license](https://github.com/sinclairzx81/typebox/blob/main/license \"license\") | [license](https://github.com/sinclairzx81/typebox/blob/main/license \"license\") | [Version 1.0.74 (](https://github.com/sinclairzx81/typebox/commit/c3ee3b08599795b534fe03654c515791286d2e96 \"Version 1.0.74 (#1505) * Annual License Update * ChangeLog * Version\") [#1505](https://github.com/sinclairzx81/typebox/pull/1505) [)](https://github.com/sinclairzx81/typebox/commit/c3ee3b08599795b534fe03654c515791286d2e96 \"Version 1.0.74 (#1505) * Annual License Update * ChangeLog * Version\") | 2 months agoJan 6, 2026 |\n| [readme.md](https://github.com/sinclairzx81/typebox/blob/main/readme.md \"readme.md\") | [readme.md](https://github.com/sinclairzx81/typebox/blob/main/readme.md \"readme.md\") | [Documentation](https://github.com/sinclairzx81/typebox/commit/fda01b4402bf94c7dbe12a73bdb960fe47a14754 \"Documentation\") | yesterdayMar 28, 2026 |\n| [tasks.ts](https://github.com/sinclairzx81/typebox/blob/main/tasks.ts \"tasks.ts\") | [tasks.ts](https://github.com/sinclairzx81/typebox/blob/main/tasks.ts \"tasks.ts\") | [Version 1.1.9 (](https://github.com/sinclairzx81/typebox/commit/686b9a29b34901edaf50fac00c523db5c1229878 \"Version 1.1.9 (#1551) * Positional Distributive Types * ChangeLog * Version * Comments\") [#1551](https://github.com/sinclairzx81/typebox/pull/1551) [)](https://github.com/sinclairzx81/typebox/commit/686b9a29b34901edaf50fac00c523db5c1229878 \"Version 1.1.9 (#1551) * Positional Distributive Types * ChangeLog * Version * Comments\") | 1 hour agoMar 29, 2026 |\n| [tsconfig.json](https://github.com/sinclairzx81/typebox/blob/main/tsconfig.json \"tsconfig.json\") | [tsconfig.json](https://github.com/sinclairzx81/typebox/blob/main/tsconfig.json \"tsconfig.json\") | [Version 1.0.68 (](https://github.com/sinclairzx81/typebox/commit/0257d8a5ca971a8057ec3c34e09764a5e1923c22 \"Version 1.0.68 (#1492) * Export Compile Function as Default * Documentation * ChangeLog * Version\") [#1492](https://github.com/sinclairzx81/typebox/pull/1492) [)](https://github.com/sinclairzx81/typebox/commit/0257d8a5ca971a8057ec3c34e09764a5e1923c22 \"Version 1.0.68 (#1492) * Export Compile Function as Default * Documentation * ChangeLog * Version\") | 3 months agoDec 25, 2025 |\n| [typebox.png](https://github.com/sinclairzx81/typebox/blob/main/typebox.png \"typebox.png\") | [typebox.png](https://github.com/sinclairzx81/typebox/blob/main/typebox.png \"typebox.png\") | [Version 1.0.0](https://github.com/sinclairzx81/typebox/commit/51e564d0420a9d7632f7acdb36c2de6a1e8b42ba \"Version 1.0.0\") | 6 months agoSep 10, 2025 |\n| View all files |\n\n## Repository files navigation\n\n# TypeBox\n\n[Permalink: TypeBox](https://github.com/sinclairzx81/typebox#typebox)\n\nJSON Schema Type Builder with Static Type Resolution for TypeScript\n\n[](https://github.com/sinclairzx81/typebox/blob/main/typebox.png)\n\n[](https://badge.fury.io/js/typebox)[](https://www.npmjs.com/package/typebox)[](https://github.com/sinclairzx81/typebox/actions/workflows/build.yml)[](https://opensource.org/licenses/MIT)\n\n## Install\n\n[Permalink: Install](https://github.com/sinclairzx81/typebox#install)\n\n```\n$ npm install typebox\n```\n\n## Usage\n\n[Permalink: Usage](https://github.com/sinclairzx81/typebox#usage)\n\n```\nimport Type from 'typebox'\n\nconst T = Type.Object({ // const T = {\n x: Type.Number(), // type: 'object',\n y: Type.Number(), // required: ['x', 'y', 'z'],\n z: Type.Number() // properties: {\n}) // x: { type: 'number' },\n // y: { type: 'number' },\n // z: { type: 'number' }\n // }\n // }\n\ntype T = Type.Static<typeof T> // type T = {\n // x: number,\n // y: number,\n // z: number\n // }\n```\n\n## Overview\n\n[Permalink: Overview](https://github.com/sinclairzx81/typebox#overview)\n\n[Documentation](https://sinclairzx81.github.io/typebox/)\n\nTypeBox is a runtime type system 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 system that can be statically checked by TypeScript and validated at runtime using standard JSON Schema.\n\nThis 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.\n\nLicense: MIT\n\n## Contents\n\n[Permalink: Contents](https://github.com/sinclairzx81/typebox#contents)\n\n- [Type](https://github.com/sinclairzx81/typebox#Type)\n- [Value](https://github.com/sinclairzx81/typebox#Value)\n- [Script](https://github.com/sinclairzx81/typebox#Script)\n- [Schema](https://github.com/sinclairzx81/typebox#Schema)\n- [Versions](https://github.com/sinclairzx81/typebox#Versions)\n- [Contribute](https://github.com/sinclairzx81/typebox#Contribute)\n\n## Type\n\n[Permalink: Type](https://github.com/sinclairzx81/typebox#type)\n\n[Documentation](https://sinclairzx81.github.io/typebox/#/docs/type/overview)\n\nTypeBox provides many functions to create JSON Schema types. Each function returns a small JSON Schema fragment that can be composed into more complex types. TypeBox includes a set of functions that are used to construct JSON Schema compliant schematics as well as a set of extended functions that return schematics for constructs native to JavaScript.\n\n## Example\n\n[Permalink: Example](https://github.com/sinclairzx81/typebox#example)\n\nThe following creates a JSON Schema type and infers with Static.\n\n```\nimport Type from 'typebox'\n\nconst T = Type.Object({ // const T = {\n x: Type.Number(), // type: 'object',\n y: Type.Number(), // required: ['x', 'y', 'z'],\n z: Type.Number() // properties: {\n}) // x: { type: 'number' },\n // y: { type: 'number' },\n // z: { type: 'number' }\n // }\n // }\n\ntype T = Type.Static<typeof T> // type T = {\n // x: number,\n // y: number,\n // z: number\n // }\n```\n\nSchema options can be passed on the last argument of any given type.\n\n```\nconst T = Type.String({ // const T = {\n format: 'email' // type: 'string',\n}) // format: 'email'\n // }\n\nconst S = Type.Number({ // const S = {\n minimum: 0, // type: 'number',\n maximum: 100 // minimum: 0,\n}) // maximum: 100\n // }\n```\n\n## Value\n\n[Permalink: Value](https://github.com/sinclairzx81/typebox#value)\n\n[Documentation](https://sinclairzx81.github.io/typebox/#/docs/value/overview)\n\nThe Value submodule provides functions for validation and other typed operations on JavaScript values. It includes functions such as Check, Parse, Clone, Encode, and Decode, as well as advanced functions for performing structural Diff and Patch operations on dynamic JavaScript values.\n\n```\nimport Value from 'typebox/value'\n```\n\n### Example\n\n[Permalink: Example](https://github.com/sinclairzx81/typebox#example-1)\n\nThe following uses the Value module to Parse a value.\n\n```\nconst T = Type.Object({\n x: Type.Number(),\n y: Type.Number(),\n z: Type.Number()\n})\n\nconst A = Value.Parse(T, { // const A: {\n x: 1, // x: number,\n y: 0, // y: number,\n z: 0 // z: number\n}) // } = ...\n```\n\n## Script\n\n[Permalink: Script](https://github.com/sinclairzx81/typebox#script)\n\n[Documentation](https://sinclairzx81.github.io/typebox/#/docs/script/overview)\n\nTypeBox includes a runtime TypeScript DSL engine that can transform TypeScript syntax into JSON Schema. The engine is implemented at runtime and within the TypeScript type system.\n\n```\n// ----------------------------------------------------------\n// Script\n// ----------------------------------------------------------\nconst T = Type.Script(`{\n x: number,\n y: string,\n z: boolean\n}`)\n\n// ----------------------------------------------------------\n// Reflect\n// ----------------------------------------------------------\nT.type // 'object'\nT.required // ['x', 'y', 'z']\nT.properties // { x: ..., y: ..., z: ... }\n\n// ----------------------------------------------------------\n// Computed\n// ----------------------------------------------------------\nconst S = Type.Script({ T }, `{\n [K in keyof T]: T[K] | null\n}`)\n\n// ----------------------------------------------------------\n// Inference\n// ----------------------------------------------------------\ntype S = Type.Static<typeof S> // type S = {\n // x: number | null,\n // y: string | null,\n // z: boolean | null\n // }\n```\n\n## Schema\n\n[Permalink: Schema](https://github.com/sinclairzx81/typebox#schema)\n\n[Documentation](https://sinclairzx81.github.io/typebox/#/docs/schema/overview)\n\nThe Schema submodule is a low level JSON Schema spec compliant validation system that supports Drafts 3 through to 2020-12. This validation system is decoupled from both Type.\\* and Value.\\* submodules and is designed to be an ultra lightweight, high performance alternative to Ajv for compiling and validating with native JSON Schema.\n\n```\nimport Schema from 'typebox/schema'\n```\n\n### Example\n\n[Permalink: Example](https://github.com/sinclairzx81/typebox#example-2)\n\nThe following uses the Schema submodule to compile and parse from JSON Schema.\n\n```\n// ----------------------------------------------------------\n// Compile\n// ----------------------------------------------------------\nconst C = Schema.Compile({\n type: 'object',\n required: ['x', 'y', 'z'],\n properties: {\n x: { type: 'number' },\n y: { type: 'number' },\n z: { type: 'number' }\n }\n})\n\n// ----------------------------------------------------------\n// Parse\n// ----------------------------------------------------------\nconst R = C.Parse({ x: 0, y: 0, z: 0 }) // const R: {\n // x: number,\n // y: number,\n // z: number\n // } = ...\n```\n\n## Versions\n\n[Permalink: Versions](https://github.com/sinclairzx81/typebox#versions)\n\nTypeBox provides two distinct versions that span two generations of the TypeScript compiler.\n\n### Version 0.x\n\n[Permalink: Version 0.x](https://github.com/sinclairzx81/typebox#version-0x)\n\n```\n$ npm install @sinclair/typebox # 0.x - LTS | TS 4-6\n```\n\nDeveloped against TypeScript 4-6 and maintained under Long Term Support (LTS) for existing infrastructure on the 0.x revision line. ESM and CJS compatible.\n\n### Version 1.x\n\n[Permalink: Version 1.x](https://github.com/sinclairzx81/typebox#version-1x)\n\n```\n$ npm install typebox # 1.x - Latest | TS 7 Native\n```\n\nDeveloped against the TypeScript 7 native compiler with advanced type inference and JSON Schema 2020-12 compliant validation, with backwards compatibility for `0.x` types. ESM only.\n\n### Additional\n\n[Permalink: Additional](https://github.com/sinclairzx81/typebox#additional)\n\nThe `1.x` version is recommended for most new projects and is the active development line that targets optimizations enabled by the TypeScript 7 native compiler. The `0.x` version is maintained under LTS for environments requiring CJS and ESM compatibility as well as support for older TypeScript compiler versions. For issues relating to `0.x` please submit them to the [TypeBox 0.x](https://github.com/sinclairzx81/sinclair-typebox) repository.\n\n## Contribute\n\n[Permalink: Contribute](https://github.com/sinclairzx81/typebox#contribute)\n\nTypeBox is open to community contribution. Please ensure you submit an issue before submitting a pull request. The TypeBox project prefers open community discussion before accepting new features.\n\n## About\n\nJSON Schema Type Builder with Static Type Resolution for TypeScript\n\n\n### Topics\n\n[typescript](https://github.com/topics/typescript \"Topic: typescript\") [jsonschema](https://github.com/topics/jsonschema \"Topic: jsonschema\")\n\n### Resources\n\n[Readme](https://github.com/sinclairzx81/typebox#readme-ov-file)\n\n### License\n\n[View license](https://github.com/sinclairzx81/typebox#License-1-ov-file)\n\n### Uh oh!\n\nThere was an error while loading. [Please reload this page](https://github.com/sinclairzx81/typebox).\n\n[Activity](https://github.com/sinclairzx81/typebox/activity)\n\n### Stars\n\n[**6.6k**\\\\\nstars](https://github.com/sinclairzx81/typebox/stargazers)\n\n### Watchers\n\n[**20**\\\\\nwatching](https://github.com/sinclairzx81/typebox/watchers)\n\n### Forks\n\n[**197**\\\\\nforks](https://github.com/sinclairzx81/typebox/forks)\n\n[Report repository](https://github.com/contact/report-content?content_url=https%3A%2F%2Fgithub.com%2Fsinclairzx81%2Ftypebox&report=sinclairzx81+%28user%29)\n\n## [Releases](https://github.com/sinclairzx81/typebox/releases)\n\n[380tags](https://github.com/sinclairzx81/typebox/tags)\n\n## [Packages\\ 0](https://github.com/users/sinclairzx81/packages?repo_name=typebox)\n\nNo packages published\n\n## [Used by 9.7m](https://github.com/sinclairzx81/typebox/network/dependents)\n\n[- \\\\\n- \\\\\n- \\\\\n- \\\\\n- \\\\\n- \\\\\n- \\\\\n- \\\\\n\\\\\n\\+ 9,742,834](https://github.com/sinclairzx81/typebox/network/dependents)\n\n## [Contributors\\ 56](https://github.com/sinclairzx81/typebox/graphs/contributors)\n\n- [](https://github.com/sinclairzx81)\n- [](https://github.com/dwickern)\n- [](https://github.com/castarco)\n- [](https://github.com/matomesc)\n- [](https://github.com/geekflyer)\n- [](https://github.com/jhewlett)\n- [](https://github.com/aleclarson)\n- [](https://github.com/hpeebles)\n- [](https://github.com/xddq)\n- [](https://github.com/DemonHa)\n- [](https://github.com/ciscoheat)\n- [](https://github.com/voda)\n- [](https://github.com/webstrand)\n- [](https://github.com/jayalfredprufrock)\n\n[\\+ 42 contributors](https://github.com/sinclairzx81/typebox/graphs/contributors)\n\n## Languages\n\n- [TypeScript99.4%](https://github.com/sinclairzx81/typebox/search?l=typescript)\n- Other0.6%\n\nYou can’t perform that action at this time.","metadata":{"og:type":"object","visitor-payload":"eyJyZWZlcnJlciI6Imh0dHBzOi8vd3d3Lmdvb2dsZS5jb20vIiwicmVxdWVzdF9pZCI6Ijk3OEY6MzBEQjk1OjMyMUZGQUE6NDAyMTkzRTo2OUM5MEIxNCIsInZpc2l0b3JfaWQiOiI5MDY0MjUyNDkzOTc0Mjc2ODg0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=","ui-target":"full","og:image":"https://repository-images.githubusercontent.com/87454905/92729364-0903-4e09-b0e1-5087b50ef8d9","analytics-location":"/<user-name>/<repo-name>","browser-stats-url":"https://api.github.com/_private/browser/stats","language":"en","viewport":"width=device-width","octolytics-dimension-repository_network_root_nwo":"sinclairzx81/typebox","hovercard-subject-tag":"repository:87454905","route-action":"disambiguate","go-import":"github.com/sinclairzx81/typebox git https://github.com/sinclairzx81/typebox.git","twitter:image":"https://repository-images.githubusercontent.com/87454905/92729364-0903-4e09-b0e1-5087b50ef8d9","request-id":"978F:30DB95:321FFAA:402193E:69C90B14","octolytics-dimension-repository_network_root_id":"87454905","fb:app_id":"1401488693436528","og:description":"JSON Schema Type Builder with Static Type Resolution for TypeScript - sinclairzx81/typebox","og:site_name":"GitHub","route-pattern":"/:user_id/:repository","fetch-nonce":"v2:def80ea9-dcda-ca81-bf71-3eb754113cf2","twitter:description":"JSON Schema Type Builder with Static Type Resolution for TypeScript - sinclairzx81/typebox","turbo-cache-control":["no-preview","no-cache"],"octolytics-url":"https://collector.github.com/github/collect","octolytics-dimension-repository_nwo":"sinclairzx81/typebox","title":"GitHub - sinclairzx81/typebox: JSON Schema Type Builder with Static Type Resolution for TypeScript · GitHub","hostname":"github.com","browser-errors-url":"https://api.github.com/_private/browser/errors","release":"51d2e33e3d1e4839c3ced5f8e35c7a47d3a60f32","disable-turbo":"false","html-safe-nonce":"0a848ea81bb9869e1aa31fe8ad95b1233df62a94a98f4b118efd0a7ddeab103f","twitter:site":"@github","ogDescription":"JSON Schema Type Builder with Static Type Resolution for TypeScript - sinclairzx81/typebox","current-catalog-service-hash":"f3abb0cc802f3d7b95fc8762b94bdcb13bf39634c40c357301c4aa1d67a256fb","ogUrl":"https://github.com/sinclairzx81/typebox","turbo-body-classes":"logged-out env-production page-responsive","ogSiteName":"GitHub","google-site-verification":"Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I","apple-itunes-app":"app-id=1477376905, app-argument=https://github.com/sinclairzx81/typebox","ogImage":"https://repository-images.githubusercontent.com/87454905/92729364-0903-4e09-b0e1-5087b50ef8d9","og:title":"GitHub - sinclairzx81/typebox: JSON Schema Type Builder with Static Type Resolution for TypeScript","route-controller":"files","octolytics-dimension-user_login":"sinclairzx81","octolytics-dimension-repository_is_fork":"false","user-login":"","ogTitle":"GitHub - sinclairzx81/typebox: JSON Schema Type Builder with Static Type Resolution for TypeScript","visitor-hmac":"d3e8f329f23ecd2638fb0c8676698d1e826975313dfcfc523f20260adbdc6cb4","octolytics-dimension-repository_id":"87454905","expected-hostname":"github.com","color-scheme":"light dark","twitter:title":"GitHub - sinclairzx81/typebox: JSON Schema Type Builder with Static Type Resolution for TypeScript","description":"JSON Schema Type Builder with Static Type Resolution for TypeScript - sinclairzx81/typebox","octolytics-dimension-repository_public":"true","octolytics-dimension-user_id":"3048342","og:image:alt":"JSON Schema Type Builder with Static Type Resolution for TypeScript - sinclairzx81/typebox","og:url":"https://github.com/sinclairzx81/typebox","twitter:card":"summary_large_image","theme-color":"#1e2327","github-keyboard-shortcuts":"repository,copilot","favicon":"https://github.githubassets.com/favicons/favicon.svg","scrapeId":"019d3953-4883-75d8-89ea-b9dafec5fa7c","sourceURL":"https://github.com/sinclairzx81/typebox","url":"https://github.com/sinclairzx81/typebox","statusCode":200,"contentType":"text/html; charset=utf-8","timezone":"America/New_York","proxyUsed":"basic","cacheState":"miss","indexId":"75d9439c-28ab-4037-b157-71068e3639ae","creditsUsed":1}},{"url":"https://github.com/sinclairzx81/typebox/issues/825","title":"Optimisations to inference in 0.32 seems to cause `ts(2589 ... - GitHub","description":"@sinclairzx81 do you expect there to be any performance implications from using schema with Value.Decode that have changed from using Composite ...","position":2,"category":"github","markdown":"[Skip to content](https://github.com/sinclairzx81/typebox/issues/825#start-of-content)\n\nYou signed in with another tab or window. [Reload](https://github.com/sinclairzx81/typebox/issues/825) to refresh your session.You signed out in another tab or window. [Reload](https://github.com/sinclairzx81/typebox/issues/825) to refresh your session.You switched accounts on another tab or window. [Reload](https://github.com/sinclairzx81/typebox/issues/825) to refresh your session.Dismiss alert\n\n{{ message }}\n\n[sinclairzx81](https://github.com/sinclairzx81)/ **[typebox](https://github.com/sinclairzx81/typebox)** Public\n\n- [Notifications](https://github.com/login?return_to=%2Fsinclairzx81%2Ftypebox) You must be signed in to change notification settings\n- [Fork\\\\\n197](https://github.com/login?return_to=%2Fsinclairzx81%2Ftypebox)\n- [Star\\\\\n6.6k](https://github.com/login?return_to=%2Fsinclairzx81%2Ftypebox)\n\n\n# Optimisations to inference in 0.32 seems to cause `ts(2589)` with composite types. \\#825\n\n[New issue](https://github.com/login?return_to=https://github.com/sinclairzx81/typebox/issues/825)\n\nCopy link\n\n[New issue](https://github.com/login?return_to=https://github.com/sinclairzx81/typebox/issues/825)\n\nCopy link\n\nClosed\n\nClosed\n\n[Optimisations to inference in 0.32 seems to cause `ts(2589)` with composite types.](https://github.com/sinclairzx81/typebox/issues/825#top)#825\n\nCopy link\n\nLabels\n\n[investigate](https://github.com/sinclairzx81/typebox/issues?q=state%3Aopen%20label%3A%22investigate%22) [todo](https://github.com/sinclairzx81/typebox/issues?q=state%3Aopen%20label%3A%22todo%22)\n\n[](https://github.com/Gnuxie)\n\n## Description\n\n[](https://github.com/Gnuxie)\n\n[Gnuxie](https://github.com/Gnuxie)\n\nopened [on Apr 10, 2024on Apr 10, 2024](https://github.com/sinclairzx81/typebox/issues/825#issue-2236093907)\n\nIssue body actions\n\nContext: [Gnuxie/matrix-protection-suite#26](https://github.com/Gnuxie/matrix-protection-suite/pull/26)\n\nI hit the limit about [here](https://github.com/Gnuxie/matrix-protection-suite/blob/bfddf00c4adb3336a61ff52bd7bfb44d6698b5c8/src/MatrixTypes/Events.ts#L95) in this file where we make extensive use of composite types to try keep the schema modular. Granted, this could be a misuse of the composite type, and I'm not sure where to go from here. FWIW these Schema were all working as of 0.31.15.\n\nI couldn't see anything specifically from [#689](https://github.com/sinclairzx81/typebox/pull/689) that would be causing this, but I could be missing something.\n\n## Activity\n\n[Next](https://github.com/sinclairzx81/typebox/issues/825?timeline_page=1)\n\n[](https://github.com/sinclairzx81)\n\n### sinclairzx81 commented on Apr 11, 2024on Apr 11, 2024\n\n[](https://github.com/sinclairzx81)\n\n[sinclairzx81](https://github.com/sinclairzx81)\n\n[on Apr 11, 2024on Apr 11, 2024](https://github.com/sinclairzx81/typebox/issues/825#issuecomment-2049197396)\n\nOwner\n\nMore actions\n\n[@Gnuxie](https://github.com/Gnuxie) Hi,\n\n> I couldn't see anything specifically from [#689](https://github.com/sinclairzx81/typebox/pull/689) that would be causing this, but I could be missing something.\n\nThere has been some recent updates made to Composite to further replicate type evaluation in TypeScript (that is to say, TypeBox is trying to compute the intersection of all types passed to Composite such that the output schema / type is an evaluated `object` type and not a `allOf` representation as would be the case for Intersect). However, the Composite evaluation is an extremely expensive thing to compute, and I think when tagged with `ReturnType` inference (instantiation expressions as per your implementation), this is likely pushing out the extents of the type system.\n\nThe recent updates for Composite were to do with Union evaluation. You can read about some of the context here [#789](https://github.com/sinclairzx81/typebox/issues/789). I believe these updates went out on 0.32.16, so if you can try 0.32.15 and just let me know if you still see the same issue, I may reinvestigate using the matrix-protection types as a basis for testing.\n\n* * *\n\n### Workaround\n\n> Granted, this could be a misuse of the composite type, and I'm not sure where to go from here\n\nSo, much of the issues here would be to do with TypeBox doing deep type evaluation on the Composite types. If it's reasonable to do so, you can swap from Composite to Intersect. The Intersect type should have the same assertion characteristics as Composite, but the schematics are a bit more \"extreme\" as each Intersect type is expressed via JSON Schema `allOf` keyword.\n\nHere's a working version of the matrix-protection types using Intersect instead of Composite.\n\n[TypeScript Link Here](https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAbzgZRgQxsAxgGhezLAEQFMsIATEvAFWSwAsSQ1aBPMEuAXzgDMoEEHADkAAQDOwAHZYANmmBQA9DA4kARhAAeIgNwAoA+WkT4qKDIDmAUQBuJaTACSROAF44NdQDoL1gAoASmMIU3MYS2krACUIIVc4Dy9ff2jg0PD8KKsAVQkSKETPb04-SMCQkzMvAGEwmEd4Et8AeQ0AKzIYAIRuIMMDEm1IWDg1Tjh7JoAeeqcmuGHG6QoJL3omFmSJkgg+OoamgD5k1AxsGYMkmJIYAFcoaVKSGd39qYcnOaOnY+ODMdDMNRvBqvBpk5kj8FlDlo41htGMw0McAvMVjAAFxwDFNIIeAFJF4+dpdLA9BDXJJwEyYnF4pw4alJXY4klpKy9Fk0qgSLCWMCYMJYnk0uAAIhoTHG6jgHxIXxgPi8DGA62QAAlWrkADJuDRcaRoEAkCRgNBYEgUOBSEDABRQcYQOAAKTQdjQcAtWAA1mgrEaTdZaWElcAwusSD4rCqROQQD5hiawHJoxJ7hoKEJFNIk0qfLsRBLmeL+qWeAMjCDoPBdnBcqZgFZpNaiBgvZ5zoQ3uoPo2pC22x2gUMRrXQ1kB83WxR2+hkiSyd1uUkAyR2W0hRHjXIAjySQA5e4gQ1QVfiuB8gXAbcisU0kTSriYU1wGRwe1yOTqshhREwAwGBwEBUYKGABQ2lIsgvjKiqLAA7mg6wFE4KrSuq-DACQcg2phgatlAGDWnAGhsOMMpyBAWBoHIIFCGahQOFAeBoKsn5oORhrvrI0BQN074HIBXBUTRdGvlwYRwMBabIfAYSSUJMowAhLoFFAzHrJhED3PJBwSGwsh4AhaqMLSbHmfcBQUVw67OkswDCU63GtlYFwOPKTpWPxxFOoBFmOdJFL3LRcjkeqPgiBW4p8NALDYqIMgwAAbAALFFD7JuAaY4gAjAArMlADsqUAMxFdFlbUkEFb8RQlqNBQAD6ho0VZG4pGUrR3ruAQko2vrSBACHSMENXUpEbESA1O5NcAFCbl1PW0fu4ochU6RUpeV5mjePWittSRPjK8jYU4AC0GZgKm2E2gA2pNpgzVJrgALoBMop1NJdTGFOdaBgMAygAMSPdNFI7ud81NMAfDYVAEg1fw0BLNoKZpngYCCHY0M2jjaAADrSAABgACrkNBwMoTXxZY2ifT+TTKHYpXKIIQgSMoCDsyAzgUNwyioRQXPwU4LwCwgMDaNIfPcMTOBE7DNm0ozUKGiGVjAF8yui-AmHCbaJqSa2cAmdgDC2osjk+ETGVliESTjUkWOKk1dJNIt0bdcKvX9dIg3DaNQTjf0gw1mM9bIIZWBxEIkIwDCmKoysiJ0Mi2yeO8Bw0IyMCnF2BCXNStwPE8Ly9pwHxR7IscgPHicnACo7h2CkbmNHtfx9CufJwi6xp1sqLor8CW5wS7hEp10bOAsCMrndPLx8PsIwE7NJLp0K5bZeutzQt2TWPHriVUkQuFDinL5IUx8PtAzYyE16nMU1MASJ7PjHqehQXtt16Cj7B1DpHRoKAM06BwA8U-A6H8BQTCIiknfTWxpMDRHoqaJ+hRTZMGkBRTCutTbIUtmhO2h1YpQHijiEQSU0okPtifOA9wmxDn3kuZae5pzMPnGgNeSRyzUlelWMcoJZSTE7kqBucJtAp37psFEOw+zZ1zvnfAFxiB-ioFcG4dxHjPHUBXPYBwxGzCUU3YE44xjgjgEYqEngJHwHhKsGR6ch65wZCPcek8SQz0aHPCkAQF7imrjHeIdclTL0xDwqepJN5+O3uKHme8L4bViCEm+dD+GCMsd2EgABpEg5EWhdRiZSakZhiJNV9Pk9+nIf47X5P-HcgDxQSgAIIMOkMAAAjvcLglTyJmzMlQOGrZ1gGwgMxBClgUFWEtiwJw2B1hkNwesQGZBFJwB5raAg0ZVSYU9HIHp751j7BWNJOAAAvQoEBzppmiIBLZOR0IyhdqhK08olKYT6RxSpoy1RRiVGc7Jnwmg22kECvpKF0CwBDAhRyFsLLEzEMTaS-ENmMQ0iRJZ-E+CFEcFgEM7UnSuAkHgDMZlCGbNNF-BGKoADqcKdbaCtD1d5ZycUISWEqElWziKcqaChO4psGVek1trQlIh1iJEIQbMpjQ4BfIALK5GQJTMIYVSJcAKPAMiFFgKEp8CWakfDQ7VnMXWOUQTsn1x7g41OsiM4iIMYcFe+dqTdmwKQcgGiS46PLlnFA0crXiJMc3M1k4aiWu2V3WxNqpF9yRIPNErjcTuMJNSLxs9YE9DukE6xPQx54GyXktgAiw5hsjlG4NI9e6OITXIzOCjnWYldUkd1aivWvB9WXPR-qg3GJHv8UNwismVsWDG6ttqnGJvCR7FNK8PHpt8N4woWb-F5pnU4JGRb8mltNcIitgpOAUD7TYlRhBPWUFeL2io11rQnrzmY4dbcD63uPaO09G9yQlKSO7Jw78BpDRGsECssqSAVKqVEmpSA-63gAaIZ8cBiagfA2wZFSyDa60ipWCsbJIPJN6HUvacHjpcGJrsNDKMMMFhENh0pCJz4H2iFfIoRBmQmoMEAA)\n\nIf you just want to test version 0.32.15 and let me know how that helps solve things, that would be great. I don't know if I'm going to be able to revert Composite back to a previous version (as the current implementation is closer the envisioned computed type), but do think there's potential to further optimize the type for the implementation you've provided. There is some pending work to do with respect to deep type evaluation (of which Composite would be involved), but I don't envision optimizations making it out until TypeBox reaches 0.33.x (which is a fair way off)\n\nFor now, give Intersect a try (which will keep you on the latest versions) and just let me know if you still run into issues on 0.32.15, I'll do some digging based on your feedback.\n\nCheers!\n\nS\n\n[](https://github.com/Gnuxie)\n\n### Gnuxie commented on Apr 11, 2024on Apr 11, 2024\n\n[](https://github.com/Gnuxie)\n\n[Gnuxie](https://github.com/Gnuxie)\n\n[on Apr 11, 2024on Apr 11, 2024](https://github.com/sinclairzx81/typebox/issues/825#issuecomment-2049545952)\n\nAuthor\n\nMore actions\n\nHi, thanks for the speedy response, I'll see what happens in 0.32.15 and report back.\n\n> Workaround\n\nFor now though, I want to add some context for why I originally moved away from `Intersect`, and there are two reasons.\n\nThe first is it's less helpful dealing with the typescript union type when trying to debug an issue, since obviously they can become so massive. It can be very difficult to see what is wrong based on the output typescript gives when working with what are believed to be (by me) compatible types. And then VSCode would also expand references to types into a massive type literal when using VSCode's feature to add missing methods when implementing classes in interfaces, and I would get annoyed trying to delete them. Which yes, is probably a silly reason 😓.\n\ne.g.\n\n```\ninterface Timeline {\n addEvent(event: RoomEvent): void;\n}\n```\n\n```\nclass StandardTimeline implements Timeline {\n addEvent(event: { ... }\n & { .... }\n & { .... }\n ) {\n throw new TypeError(\"Unimplemented\");\n }\n}\n```\n\n> However, the Composite evaluation is an extremely expensive thing to compute, and I think when tagged with ReturnType inference (instantiation expressions as per your implementation), this is likely pushing out the extents of the type system.\n\nI see, I don't really understand how the type system works but I trust you. I'll follow up shortly\n\n[](https://github.com/Gnuxie)\n\n### Gnuxie commented on Apr 11, 2024on Apr 11, 2024\n\n[](https://github.com/Gnuxie)\n\n[Gnuxie](https://github.com/Gnuxie)\n\n[on Apr 11, 2024on Apr 11, 2024](https://github.com/sinclairzx81/typebox/issues/825#issuecomment-2049606732)\n\nAuthor\n\nMore actions\n\nThe problem seems to be introduced within `0.32.0`.\n\n[](https://github.com/dwickern)\n\n### dwickern commented on Apr 18, 2024on Apr 18, 2024\n\n[](https://github.com/dwickern)\n\n[dwickern](https://github.com/dwickern)\n\n[on Apr 18, 2024on Apr 18, 2024](https://github.com/sinclairzx81/typebox/issues/825#issuecomment-2065119974)\n\nContributor\n\nMore actions\n\nI'm seeing this issue starting in 0.32.9\n\n[](https://github.com/sinclairzx81)\n\n### sinclairzx81 commented on Apr 18, 2024on Apr 18, 2024\n\n[](https://github.com/sinclairzx81)\n\n[sinclairzx81](https://github.com/sinclairzx81)\n\n[on Apr 18, 2024on Apr 18, 2024](https://github.com/sinclairzx81/typebox/issues/825#issuecomment-2065159364)\n\nOwner\n\nMore actions\n\n[@dwickern](https://github.com/dwickern) Heya,\n\nHmmm, not sure if I'll be able to revert recent Composite functionality, ill have to try and optimize around it. Would it be possible for you share a repro of your type setup? (just wanting to take a look at some of the downstream use cases where Composite is popping out). Any info / reproduction you can provide will be helpful.\n\n[sinclairzx81](https://github.com/sinclairzx81)\n\nadded\n\n[investigate](https://github.com/sinclairzx81/typebox/issues?q=state%3Aopen%20label%3A%22investigate%22)\n\n[on Apr 18, 2024on Apr 18, 2024](https://github.com/sinclairzx81/typebox/issues/825#event-12529273831)\n\n[](https://github.com/Gnuxie)\n\n### Gnuxie commented on Apr 18, 2024on Apr 18, 2024\n\n[](https://github.com/Gnuxie)\n\n[Gnuxie](https://github.com/Gnuxie)\n\n[on Apr 18, 2024on Apr 18, 2024](https://github.com/sinclairzx81/typebox/issues/825#issuecomment-2065398650)\n\nAuthor\n\nMore actions\n\nJust an update before anything goes further, i suspect that upgrading typescript can trigger the same problem in `0.31.*` but haven't investigated yet.\n\n[](https://github.com/sinclairzx81)\n\n### sinclairzx81 commented on Apr 19, 2024on Apr 19, 2024\n\n[](https://github.com/sinclairzx81)\n\n[sinclairzx81](https://github.com/sinclairzx81)\n\n[on Apr 19, 2024on Apr 19, 2024](https://github.com/sinclairzx81/typebox/issues/825#issuecomment-2065755677)\n\nOwner\n\nMore actions\n\n[@Gnuxie](https://github.com/Gnuxie) Hi,\n\nSo, I've dug a bit deeper into this issue using [this code](https://github.com/Gnuxie/matrix-protection-suite/blob/bfddf00c4adb3336a61ff52bd7bfb44d6698b5c8/src/MatrixTypes/Events.ts#L95) as a basis. I do think TypeBox has introduced a deep inference issue on 0.32.0 which I'm going to try and resolve through optimization, however resolving it is difficult as the inference is already quite optimized.\n\nCurrently 0.32.0 inference / evaluation of Composite is correct and inline with TS evaluation, it's just that in order to replicate TS evaluation, the work TB needs to do is very top heavy (with this issue specifically seemingly only popping out on deep instantiation expression via ReturnType, although I've been able to push it out in a couple of other ways)\n\nIll spend some more time today looking for temporary solution, however I don't anticipate a fix will be possible on 0.32.0 as the inference infrastructure may require some refactoring (which would be more indicative of a 0.33.0 minor revision). As mentioned tho, you can swap from Composite to Intersect (which will produce the same inference (non-normalized) and a non-evaluated `allOf` schema representation). This may serve as a temporary workaround.\n\nWill keep you posted\n\nS\n\n[](https://github.com/sinclairzx81)\n\n### sinclairzx81 commented on Apr 20, 2024on Apr 20, 2024\n\n[](https://github.com/sinclairzx81)\n\n[sinclairzx81](https://github.com/sinclairzx81)\n\n[on Apr 20, 2024on Apr 20, 2024](https://github.com/sinclairzx81/typebox/issues/825#issuecomment-2067795724)\n\nOwner\n\nMore actions\n\n[@Gnuxie](https://github.com/Gnuxie) Hi,\n\nSo have investigated this issue further, and unfortunately I don't think I'm going to be able to resolve this on 0.32.x. As it stands, things are already as optimized as I can get them using the current inference strategy, and I think to go further, I'll need to investigate an alternative strategy which will take time (and a revision bump).\n\nAs it stands, to solve this issue on the current revision would involve removing inference logic which would make Composite \"less correct\", it's just that correct-ness in this case has come at a instantiation depth cost....which is unfortunate.\n\n* * *\n\n### Revisiting Intersect (Workaround)\n\n> The first is it's less helpful dealing with the typescript union type when trying to debug an issue, since obviously they can become so massive. It can be very difficult to see what is wrong based on the output typescript gives when working with what are believed to be (by me) compatible types. And then VSCode would also expand references to types into a massive type literal when using VSCode's feature to add missing methods when implementing classes in interfaces, and I would get annoyed trying to delete them. Which yes, is probably a silly reason 😓.\n\nI do think it's reasonable to want presentable types! However I would encourage you to revisit Intersect as a workaround as there are options available to you to leverage Intersect while still obtaining flattened types. TypeBox does export a `Evaluate` utility type which performs a \"static type level\" evaluate (producing the same inference as Composite) on intersected and unioned types.\n\n```\nimport { Evaluate } from '@sinclair/typebox'\n\ntype T = Evaluate<{ // type T = { a: number, b: number }\n a: number\n} & {\n b: number\n}>\n```\n\nThe following is an update to the provided reference issue code using Intersect + Evaluate to flatten out the types.\n\n[src/MatrixTypes/Events.ts (implemented with Intersect + Evaluate)](https://www.typescriptlang.org/play?&a=1#code/JYWwDg9gTgLgBAbzgZRgQxsAxgEQKZYQAmeANHACrJYAWeIa5FAnmGXAKIBuaANgK4Y8cAL5wAZlAgg4AcgACAZ2AA7LLzTAoAehis8AIwgAPWQG4AUBe3aUbLMD7AAXniIp0mLHAC0nHgJCinAAkioweFCKBJgQKsFowQDyBgBWMXB6bBZ4xpCwmfoeGNgAPBRwuREqRMFUtPRoAHxwALz+fIIRpagluATEeOVNTZbWthR00XAA7pHCoPkwihaE8fCoUKoA5tx44SE4bZT6AHSbOwAUAJSWa4obMFsq2wBKENKHxyxs509Xt1WcQeHme2wAqtEoF92j88H8wTcxjY4ABBYJsKBwQgkOBQPDieZqeGnU5A9aUADCcWq8FhZxS6SwMEuCBEgJyeWg8Cywj24VK1PC+3gVX2tUo1DoDGOvIg4ipNJFLXavS8pQscDgrzwMH4UBUcNKcoV-JggqV4RGFlGnKW2OB8DNxwtwvClWM1Ql9WlzUuQtpAC44AGRdc2k1NSdfoyYqyo1q1kGQ5aYKQE4U2MG4QirggM1qSIosFswLEVIGC1q4AAiSbCXlweWVLgi06UGjAYLIAASSXBABkjgZhCo0CA8IowGgsG44MoQMANFiYBA4AApNA8ODTrAAazQ21H452DpUrfCwGBlVO23bskIIFOuXHYF48MU-AMRGkmhUz4vGBTl5WQa3TatRGucDILGXJ7UbcF4mAbYVDcHAMDQY41TKE04EQ5QULQjDbTg7kzxBfDkNQoh0PQb4GTSON8y1Q88GzBkyyvMdeEuDMcwAOX4EARygeMIMLScS2ATi4krcTq1ketMlABYVDgRdeF4LsBhqYIYBoDA4AM4I8A0MBoncZRiUyOgWxFWZEnnNsOy7CRgFM9xXKPVCoCEdwDGYGzhF4CAsD4IzpEnSJWygcg0BqdS0ECkc4FUQgoHxZlUoVfTgtC8LMAnJs1MM99EngOJhGbXLMhmNcoRi4JXIgfgKoVRRmDUcgZk7WhsXi-r+GmGrWMyNc8GAXKsRS1DthKVsmyxbZ8SEFcDLUya4BnPU+F4QKu1OWRoIg8RoAYGBg1kVQYAANgAFiOqsX3Ad9gwARgAVhugB2O6AGZvuOyCoygqN8SIba3AAfRHMKhrY6N4SSGTuMuHNEL3FQIBmFQblBrUnnixRtq4qHgCIdiYxRvheIgnMLheMTxKLKSUbk+S5CU9R3PCHxPzAN93PcABtQn4hJuJQhwABdS5tG5kU+eiyIfDQMBgG0ABiMXieZLifHJkVgHEdyoigiRoA9V933IMApC4Q33AdtAAB0VAAAwABXBCptCh86tmMeWtJFbQuD+7QpGkRRtAQKOQBCIgRG0aIaljvBALhZOEBgYwVETkR3dIN3jaC7EQ-dEdT22YALzLjP7NcmriaKyrZl6mgnPdSbTjdx6IPZEHoLtjOoaTEVKaR6mePRlRMex3HrlB9lYK5ApG2QTqsHeaQzVdWkPS9OopUaWV9GbChQytLDPDKKMdT1A0jVwze1B3kA96vmBrRItf4HuDYW937OnaPveyYpdKSgaAwJo-pUzBi-uGVokYtQ5jCBEKIcZhYZjNHAt0MB8bVhzLGZkTMIIN3CGTCmoIdhmkOEDLUqcSBQGDAzCEUJ6FVmgMhVQUMGqRChssSepxBLCUiGQ5mklSzlnZhzTmKkHivlSmpDSWlohrAlJLbhNcxyYBeBFCc-CsQ9X2DZVyFD4AzEcqnIC-cOanSgOdS6117p2IHoQiC-AkKEWocQ6elxKI+NomgDxkFoLSw5KRdeRRgGATAe6CB3oT4ynaLhS+qYVTFHVPfXU+pDT6GNOfBUsSRTxO-pGX+9oAHag+B-QCLov6H3FMfaBfov4INTEglBiNTjoMiOolk2CIKv23rU3BiCgbEMYqQ5i4l45UNYf8F479OHuPCRyapao8AAGk8CBXpDGaZLJZmKIiFDPcezhFsIkSzaRXFZHVhrKiOAXjgAAEd+DCAuYFHq2BO4kBNqhPStkIAxRmFsPR2wnIMEvFgYIDizEYncrOJsCp47zk8PCFywQAifNSsEeU1QtpwFcFIHw74Xj6QxWCdsSkR6pxRdVTswRvmJQucC8x9TMJbP8G2N2PLvnBEUbAU8MxJqdwGu7eQ7str4jxFFKArZ3AIvxISfEahTzwyxIcRQ5BPx9UcuiicYiojtgAOrivrsYWcKNUXEsJDMOy4RdUYqEE65YTlLGWswjXOuWrZDBC+I5ZumK4CsoALLgmQBUOIe04ApWiPAAKNlDJatOGBKM7J0wrysFEnkRQRlbM-qmJpkCfSn1SUUxU+CVRRm4J0IQPRb79BxEMB+eTn5VsLZi4tNaRiVLIpsreRb6mgMaYklpvpYHtJTPgrpUY0HCkwaQ4WIySnhDwbSc2WzdnMAiaveCBae1xPHZ6ZpUDfRnzYBfL+tatTYSwKUdtT8Ckv2PaU29IxLB5vIo8IQIC4BlNLUk1p074Gzq3RGBdZw+nLsGeulkEysk7L2fu3Nf9MzCAuALNwI77KqmbYU69CpsNsCIHhq036MObP+Dh8j773QHKRkcpm49wjCIxljHGNxoKnLwOcy5PTrlIFudJGRnNbLuz4wJ5gMqEU1QsYdMJUZeRXKWdsVkcBRNswk8Id2vI5OWwU4BJTWaoxMMiIssEkJIicJzVYIAA)\n\nThis is probably the best option I can advise at this time until I get a chance to really dig in and restructure some of the internals to support deeper inference. The above would keep you on the newer versions of TB. The only other thing I can think of would be to keep to pre 0.32.x revisions until this issue is resolved on 0.33.x. In terms of timings, I'll be aiming for minor revision sometime around late June (tentative).\n\nHope this helps in the interim.\n\nS\n\n[sinclairzx81](https://github.com/sinclairzx81)\n\nadded\n\n[todo](https://github.com/sinclairzx81/typebox/issues?q=state%3Aopen%20label%3A%22todo%22)\n\n[on Apr 20, 2024on Apr 20, 2024](https://github.com/sinclairzx81/typebox/issues/825#event-12548688697)\n\n[](https://github.com/Gnuxie)\n\n### Gnuxie commented on Apr 20, 2024on Apr 20, 2024\n\n[](https://github.com/Gnuxie)\n\n[Gnuxie](https://github.com/Gnuxie)\n\n[on Apr 20, 2024on Apr 20, 2024](https://github.com/sinclairzx81/typebox/issues/825#issuecomment-2067804936)\n\nAuthor\n\nMore actions\n\n[@sinclairzx81](https://github.com/sinclairzx81) Thank you so much for the follow up, that's ok! The `Intersect` \\+ `Evaluate` solution looks perfect to me, and while I'm not in a hurry to upgrade to `0.32.x`, I will incorporate it when I can.\n\n👍React with 👍1sinclairzx81\n\n[Gnuxie](https://github.com/Gnuxie)\n\nadded a commit that references this issue [on Apr 22, 2024on Apr 22, 2024](https://github.com/sinclairzx81/typebox/issues/825#event-12564265603)\n\n[Update to typebox 0.32.22](https://github.com/Gnuxie/matrix-protection-suite/commit/1d629170e9f6a0d8fa1dcc0d2ed8816fbb641c8f)\n\n...\n\n[1d62917](https://github.com/Gnuxie/matrix-protection-suite/commit/1d629170e9f6a0d8fa1dcc0d2ed8816fbb641c8f)\n\n[Gnuxie](https://github.com/Gnuxie)\n\nmentioned this [on Apr 22, 2024on Apr 22, 2024](https://github.com/sinclairzx81/typebox/issues/825#event-1380739280)\n\n- [Update to typebox 0.32.22 Gnuxie/matrix-protection-suite#29](https://github.com/Gnuxie/matrix-protection-suite/pull/29)\n\n\n[](https://github.com/Gnuxie)\n\n### Gnuxie commented on Apr 22, 2024on Apr 22, 2024\n\n[](https://github.com/Gnuxie)\n\n[Gnuxie](https://github.com/Gnuxie)\n\n[on Apr 22, 2024on Apr 22, 2024](https://github.com/sinclairzx81/typebox/issues/825#issuecomment-2070638733)\n\nAuthor\n\nMore actions\n\nWhile not an issue, just an observation for who might be following along, a side effect from moving from `Intersect` to `Composite` is that you can get duplicate errors from `Value.Errors` when the intersect has duplicate schema for some properties.\n\n[Gnuxie](https://github.com/Gnuxie)\n\nadded a commit that references this issue [on Apr 22, 2024on Apr 22, 2024](https://github.com/sinclairzx81/typebox/issues/825#event-12564404954)\n\n[Update to typebox 0.32.22](https://github.com/Gnuxie/matrix-protection-suite/commit/01f765610697738df967053dd53a5ebac462cec9)\n\n...\n\n[01f7656](https://github.com/Gnuxie/matrix-protection-suite/commit/01f765610697738df967053dd53a5ebac462cec9)\n\n### 16 remaining items\n\nLoad more\n\nLoading\n\n[Sign up for free](https://github.com/signup?return_to=https://github.com/sinclairzx81/typebox/issues/825)**to join this conversation on GitHub.** Already have an account? [Sign in to comment](https://github.com/login?return_to=https://github.com/sinclairzx81/typebox/issues/825)\n\n## Metadata\n\n## Metadata\n\n### Assignees\n\nNo one assigned\n\n### Labels\n\n[investigate](https://github.com/sinclairzx81/typebox/issues?q=state%3Aopen%20label%3A%22investigate%22) [todo](https://github.com/sinclairzx81/typebox/issues?q=state%3Aopen%20label%3A%22todo%22)\n\n### Projects\n\nNo projects\n\n### Milestone\n\nNo milestone\n\n### Relationships\n\nNone yet\n\n### Development\n\nCode with agent mode\n\nSelect code repository\n\nNo branches or pull requests\n\n### Participants\n\n[](https://github.com/dwickern)[](https://github.com/sinclairzx81)[](https://github.com/Gnuxie)[](https://github.com/aadito123)\n\n## Issue actions\n\nYou can’t perform that action at this time.","metadata":{"twitter:title":"Optimisations to inference in 0.32 seems to cause `ts(2589)` with composite types. · Issue #825 · sinclairzx81/typebox","og:author:username":"Gnuxie","og:image:height":"600","user-login":"","twitter:image":"https://opengraph.githubassets.com/1a6e1c99cfd49a7d01bc55ec1a9de25bcce6cc39948420d753bdfb2d88856683/sinclairzx81/typebox/issues/825","color-scheme":"light dark","og:type":"object","octolytics-dimension-repository_nwo":"sinclairzx81/typebox","ogImage":"https://opengraph.githubassets.com/1a6e1c99cfd49a7d01bc55ec1a9de25bcce6cc39948420d753bdfb2d88856683/sinclairzx81/typebox/issues/825","twitter:card":"summary_large_image","browser-stats-url":"https://api.github.com/_private/browser/stats","hovercard-subject-tag":"issue:2236093907","github-keyboard-shortcuts":"repository,issues,copilot","go-import":"github.com/sinclairzx81/typebox git https://github.com/sinclairzx81/typebox.git","octolytics-dimension-repository_public":"true","twitter:site":"@github","analytics-location":"/<user-name>/<repo-name>/voltron/issues_fragments/issue_layout","og:url":"https://github.com/sinclairzx81/typebox/issues/825","html-safe-nonce":"4eeac5856923bdbe029cedac73e1bb3af51e218021e72a813c8d3fc411133b1e","route-pattern":"/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)","google-site-verification":"Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I","title":"Optimisations to inference in 0.32 seems to cause `ts(2589)` with composite types. · Issue #825 · sinclairzx81/typebox","description":"Context: Gnuxie/matrix-protection-suite#26 I hit the limit about here in this file where we make extensive use of composite types to try keep the schema modular. Granted, this could be a misuse of the composite type, and I'm not sure whe...","hostname":"github.com","release":"51d2e33e3d1e4839c3ced5f8e35c7a47d3a60f32","twitter:description":"Context: Gnuxie/matrix-protection-suite#26 I hit the limit about here in this file where we make extensive use of composite types to try keep the schema modular. Granted, this could be a misuse of ...","og:site_name":"GitHub","octolytics-dimension-user_login":"sinclairzx81","ui-target":"full","browser-errors-url":"https://api.github.com/_private/browser/errors","og:title":"Optimisations to inference in 0.32 seems to cause `ts(2589)` with composite types. · Issue #825 · sinclairzx81/typebox","request-id":"A75F:2658B8:4740AB3:5B6835C:69C90B14","og:image:width":"1200","current-catalog-service-hash":"81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114","octolytics-dimension-repository_id":"87454905","expected-hostname":"github.com","octolytics-dimension-repository_network_root_id":"87454905","octolytics-url":"https://collector.github.com/github/collect","viewport":"width=device-width","ogTitle":"Optimisations to inference in 0.32 seems to cause `ts(2589)` with composite types. · Issue #825 · sinclairzx81/typebox","theme-color":"#1e2327","turbo-cache-control":"no-preview","route-action":"issue_layout","og:image:alt":"Context: Gnuxie/matrix-protection-suite#26 I hit the limit about here in this file where we make extensive use of composite types to try keep the schema modular. Granted, this could be a misuse of ...","disable-turbo":"false","octolytics-dimension-user_id":"3048342","language":"en","apple-itunes-app":"app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/sinclairzx81/typebox/825/issue_layout","ogUrl":"https://github.com/sinclairzx81/typebox/issues/825","visitor-payload":"eyJyZWZlcnJlciI6Imh0dHBzOi8vd3d3Lmdvb2dsZS5jb20vIiwicmVxdWVzdF9pZCI6IkE3NUY6MjY1OEI4OjQ3NDBBQjM6NUI2ODM1Qzo2OUM5MEIxNCIsInZpc2l0b3JfaWQiOiI3MzAwNDAwNjUwNjEyNDQzOTI0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=","visitor-hmac":"63cdce5078e8d7d1ce30a2d3c06980c07b31a075dcfe81469cf29b58f4eaecc0","octolytics-dimension-repository_network_root_nwo":"sinclairzx81/typebox","turbo-body-classes":"logged-out env-production page-responsive","fetch-nonce":"v2:3e3f9fc3-bf26-7542-ad2f-5df9bd46e52c","fb:app_id":"1401488693436528","og:description":"Context: Gnuxie/matrix-protection-suite#26 I hit the limit about here in this file where we make extensive use of composite types to try keep the schema modular. Granted, this could be a misuse of ...","ogDescription":"Context: Gnuxie/matrix-protection-suite#26 I hit the limit about here in this file where we make extensive use of composite types to try keep the schema modular. Granted, this could be a misuse of ...","octolytics-dimension-repository_is_fork":"false","ogSiteName":"GitHub","route-controller":"voltron_issues_fragments","og:image":"https://opengraph.githubassets.com/1a6e1c99cfd49a7d01bc55ec1a9de25bcce6cc39948420d753bdfb2d88856683/sinclairzx81/typebox/issues/825","favicon":"https://github.githubassets.com/favicons/favicon.svg","scrapeId":"019d3953-4883-75d8-89ea-bc29fbf9da0c","sourceURL":"https://github.com/sinclairzx81/typebox/issues/825","url":"https://github.com/sinclairzx81/typebox/issues/825","statusCode":200,"contentType":"text/html; charset=utf-8","timezone":"America/New_York","proxyUsed":"basic","cacheState":"miss","indexId":"1e0cfaf9-1e61-44b9-8a9c-f6a1e30b7a45","creditsUsed":1}},{"url":"https://www.reddit.com/r/typescript/comments/1nj39lu/introducing_typebox_10_a_runtime_type_system_for/","title":"Introducing TypeBox 1.0: A Runtime Type System for JavaScript","description":"Overall, I think the biggest difference is that TypeBox is based on industry specifications first, is focused on high performance server ...","position":3},{"url":"https://www.npmjs.com/package/@sinclair/typebox","title":"@sinclair/typebox - npm","description":"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 ...","position":4,"markdown":"# @sinclair/typebox \n\n0.34.49 • Public • Published a day ago\n\n- [Readme](https://www.npmjs.com/package/@sinclair/typebox?activeTab=readme)\n- [Code Beta](https://www.npmjs.com/package/@sinclair/typebox?activeTab=code)\n- [0 Dependencies](https://www.npmjs.com/package/@sinclair/typebox?activeTab=dependencies)\n- [6088 Dependents](https://www.npmjs.com/package/@sinclair/typebox?activeTab=dependents)\n- [386 Versions](https://www.npmjs.com/package/@sinclair/typebox?activeTab=versions)\n\n# Sinclair TypeBox\n\n[Permalink: Sinclair TypeBox](https://www.npmjs.com/package/@sinclair/typebox#sinclair-typebox)\n\nJson Schema Type Builder with Static Type Resolution for TypeScript\n\n\n\n[](https://badge.fury.io/js/%40sinclair%2Ftypebox)[](https://www.npmjs.com/package/%40sinclair%2Ftypebox)[](https://github.com/sinclairzx81/typebox/actions/workflows/build.yml)[](https://opensource.org/licenses/MIT)\n\n## Install\n\n[Permalink: Install](https://www.npmjs.com/package/@sinclair/typebox#install)\n\nFor the latest version use [TypeBox 1.x](https://github.com/sinclairzx81/typebox)\n\n```\n$ npm install @sinclair/typebox # TypeBox 0.x - Long Term Support\n\n$ npm install typebox # TypeBox 1.x - Latest\n```\n\n## Example\n\n[Permalink: Example](https://www.npmjs.com/package/@sinclair/typebox#example)\n\n```\nimport { Type, type Static } from '@sinclair/typebox'\n\nconst T = Type.Object({ // const T = {\n x: Type.Number(), // type: 'object',\n y: Type.Number(), // required: ['x', 'y', 'z'],\n z: Type.Number() // properties: {\n}) // x: { type: 'number' },\n // y: { type: 'number' },\n // z: { type: 'number' }\n // }\n // }\n\ntype T = Static<typeof T> // type T = {\n // x: number,\n // y: number,\n // z: number\n // }\n```\n\n## Overview\n\n[Permalink: Overview](https://www.npmjs.com/package/@sinclair/typebox#overview)\n\nTypeBox 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.\n\nThis 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.\n\nLicense MIT\n\n## Contents\n\n[Permalink: Contents](https://www.npmjs.com/package/@sinclair/typebox#contents)\n\n- [Install](https://www.npmjs.com/package/@sinclair/typebox#install)\n- [Overview](https://www.npmjs.com/package/@sinclair/typebox#overview)\n- [Usage](https://www.npmjs.com/package/@sinclair/typebox#usage)\n- [Types](https://www.npmjs.com/package/@sinclair/typebox#types) - [Json](https://www.npmjs.com/package/@sinclair/typebox#types-json)\n - [JavaScript](https://www.npmjs.com/package/@sinclair/typebox#types-javascript)\n - [Options](https://www.npmjs.com/package/@sinclair/typebox#types-options)\n - [Properties](https://www.npmjs.com/package/@sinclair/typebox#types-properties)\n - [Generics](https://www.npmjs.com/package/@sinclair/typebox#types-generics)\n - [Recursive](https://www.npmjs.com/package/@sinclair/typebox#types-recursive)\n - [Modules](https://www.npmjs.com/package/@sinclair/typebox#types-modules)\n - [Template Literal](https://www.npmjs.com/package/@sinclair/typebox#types-template-literal)\n - [Indexed](https://www.npmjs.com/package/@sinclair/typebox#types-indexed)\n - [Mapped](https://www.npmjs.com/package/@sinclair/typebox#types-mapped)\n - [Conditional](https://www.npmjs.com/package/@sinclair/typebox#types-conditional)\n - [Transform](https://www.npmjs.com/package/@sinclair/typebox#types-transform)\n - [Guard](https://www.npmjs.com/package/@sinclair/typebox#types-guard)\n - [Unsafe](https://www.npmjs.com/package/@sinclair/typebox#types-unsafe)\n- [Values](https://www.npmjs.com/package/@sinclair/typebox#values) - [Assert](https://www.npmjs.com/package/@sinclair/typebox#values-assert)\n - [Create](https://www.npmjs.com/package/@sinclair/typebox#values-create)\n - [Clone](https://www.npmjs.com/package/@sinclair/typebox#values-clone)\n - [Check](https://www.npmjs.com/package/@sinclair/typebox#values-check)\n - [Convert](https://www.npmjs.com/package/@sinclair/typebox#values-convert)\n - [Default](https://www.npmjs.com/package/@sinclair/typebox#values-default)\n - [Clean](https://www.npmjs.com/package/@sinclair/typebox#values-clean)\n - [Cast](https://www.npmjs.com/package/@sinclair/typebox#values-cast)\n - [Decode](https://www.npmjs.com/package/@sinclair/typebox#values-decode)\n - [Encode](https://www.npmjs.com/package/@sinclair/typebox#values-decode)\n - [Parse](https://www.npmjs.com/package/@sinclair/typebox#values-parse)\n - [Equal](https://www.npmjs.com/package/@sinclair/typebox#values-equal)\n - [Hash](https://www.npmjs.com/package/@sinclair/typebox#values-hash)\n - [Diff](https://www.npmjs.com/package/@sinclair/typebox#values-diff)\n - [Patch](https://www.npmjs.com/package/@sinclair/typebox#values-patch)\n - [Errors](https://www.npmjs.com/package/@sinclair/typebox#values-errors)\n - [Mutate](https://www.npmjs.com/package/@sinclair/typebox#values-mutate)\n - [Pointer](https://www.npmjs.com/package/@sinclair/typebox#values-pointer)\n- [Syntax](https://www.npmjs.com/package/@sinclair/typebox#syntax) - [Create](https://www.npmjs.com/package/@sinclair/typebox#syntax-create)\n - [Parameters](https://www.npmjs.com/package/@sinclair/typebox#syntax-parameters)\n - [Generics](https://www.npmjs.com/package/@sinclair/typebox#syntax-generics)\n - [Options](https://www.npmjs.com/package/@sinclair/typebox#syntax-options)\n - [NoInfer](https://www.npmjs.com/package/@sinclair/typebox#syntax-no-infer)\n- [TypeRegistry](https://www.npmjs.com/package/@sinclair/typebox#typeregistry) - [Type](https://www.npmjs.com/package/@sinclair/typebox#typeregistry-type)\n - [Format](https://www.npmjs.com/package/@sinclair/typebox#typeregistry-format)\n- [TypeCheck](https://www.npmjs.com/package/@sinclair/typebox#typecheck) - [Ajv](https://www.npmjs.com/package/@sinclair/typebox#typecheck-ajv)\n - [TypeCompiler](https://www.npmjs.com/package/@sinclair/typebox#typecheck-typecompiler)\n- [TypeMap](https://www.npmjs.com/package/@sinclair/typebox#typemap) - [Usage](https://www.npmjs.com/package/@sinclair/typebox#typemap-usage)\n- [TypeSystem](https://www.npmjs.com/package/@sinclair/typebox#typesystem) - [Policies](https://www.npmjs.com/package/@sinclair/typebox#typesystem-policies)\n- [Error Function](https://www.npmjs.com/package/@sinclair/typebox#error-function)\n- [Workbench](https://www.npmjs.com/package/@sinclair/typebox#workbench)\n- [Codegen](https://www.npmjs.com/package/@sinclair/typebox#codegen)\n- [Ecosystem](https://www.npmjs.com/package/@sinclair/typebox#ecosystem)\n- [Benchmark](https://www.npmjs.com/package/@sinclair/typebox#benchmark) - [Compile](https://www.npmjs.com/package/@sinclair/typebox#benchmark-compile)\n - [Validate](https://www.npmjs.com/package/@sinclair/typebox#benchmark-validate)\n - [Compression](https://www.npmjs.com/package/@sinclair/typebox#benchmark-compression)\n- [Contribute](https://www.npmjs.com/package/@sinclair/typebox#contribute)\n\n## Usage\n\n[Permalink: Usage](https://www.npmjs.com/package/@sinclair/typebox#usage)\n\nThe following shows general usage.\n\n```\nimport { Type, type Static } from '@sinclair/typebox'\n\n//--------------------------------------------------------------------------------------------\n//\n// Let's say you have the following type ...\n//\n//--------------------------------------------------------------------------------------------\n\ntype T = {\n id: string,\n name: string,\n timestamp: number\n}\n\n//--------------------------------------------------------------------------------------------\n//\n// ... you can express this type in the following way.\n//\n//--------------------------------------------------------------------------------------------\n\nconst T = Type.Object({ // const T = {\n id: Type.String(), // type: 'object',\n name: Type.String(), // properties: {\n timestamp: Type.Integer() // id: {\n}) // type: 'string'\n // },\n // name: {\n // type: 'string'\n // },\n // timestamp: {\n // type: 'integer'\n // }\n // },\n // required: [\\\n // 'id',\\\n // 'name',\\\n // 'timestamp'\\\n // ]\n // }\n\n//--------------------------------------------------------------------------------------------\n//\n// ... then infer back to the original static type this way.\n//\n//--------------------------------------------------------------------------------------------\n\ntype T = Static<typeof T> // type T = {\n // id: string,\n // name: string,\n // timestamp: number\n // }\n\n//--------------------------------------------------------------------------------------------\n//\n// ... or use the type to parse JavaScript values.\n//\n//--------------------------------------------------------------------------------------------\n\nimport { Value } from '@sinclair/typebox/value'\n\nconst R = Value.Parse(T, value) // const R: {\n // id: string,\n // name: string,\n // timestamp: number\n // }\n```\n\n## Types\n\n[Permalink: Types](https://www.npmjs.com/package/@sinclair/typebox#types)\n\nTypeBox types are Json Schema fragments that compose into more complex types. Each fragment is structured such that any Json Schema compliant validator can runtime assert a value the same way TypeScript will statically assert a type. TypeBox offers a set of Json Types which are used to create Json Schema compliant schematics as well as a JavaScript type set used to create schematics for constructs native to JavaScript.\n\n### Json Types\n\n[Permalink: Json Types](https://www.npmjs.com/package/@sinclair/typebox#json-types)\n\nThe following table lists the supported Json types. These types are fully compatible with the Json Schema Draft 7 specification.\n\n```\n┌────────────────────────────────┬─────────────────────────────┬────────────────────────────────┐\n│ TypeBox │ TypeScript │ Json Schema │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Any() │ type T = any │ const T = { } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Unknown() │ type T = unknown │ const T = { } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.String() │ type T = string │ const T = { │\n│ │ │ type: 'string' │\n│ │ │ } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Number() │ type T = number │ const T = { │\n│ │ │ type: 'number' │\n│ │ │ } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Integer() │ type T = number │ const T = { │\n│ │ │ type: 'integer' │\n│ │ │ } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Boolean() │ type T = boolean │ const T = { │\n│ │ │ type: 'boolean' │\n│ │ │ } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Null() │ type T = null │ const T = { │\n│ │ │ type: 'null' │\n│ │ │ } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Literal(42) │ type T = 42 │ const T = { │\n│ │ │ const: 42, │\n│ │ │ type: 'number' │\n│ │ │ } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Array( │ type T = number[] │ const T = { │\n│ Type.Number() │ │ type: 'array', │\n│ ) │ │ items: { │\n│ │ │ type: 'number' │\n│ │ │ } │\n│ │ │ } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Object({ │ type T = { │ const T = { │\n│ x: Type.Number(), │ x: number, │ type: 'object', │\n│ y: Type.Number() │ y: number │ required: ['x', 'y'], │\n│ }) │ } │ properties: { │\n│ │ │ x: { │\n│ │ │ type: 'number' │\n│ │ │ }, │\n│ │ │ y: { │\n│ │ │ type: 'number' │\n│ │ │ } │\n│ │ │ } │\n│ │ │ } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Tuple([ │ type T = [number, number] │ const T = { │\\\n│ Type.Number(), │ │ type: 'array', │\\\n│ Type.Number() │ │ items: [{ │\\\n│ ]) │ │ type: 'number' │\\\n│ │ │ }, { │\\\n│ │ │ type: 'number' │\\\n│ │ │ }], │\n│ │ │ additionalItems: false, │\n│ │ │ minItems: 2, │\n│ │ │ maxItems: 2 │\n│ │ │ } │\n│ │ │ │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ enum Foo { │ enum Foo { │ const T = { │\n│ A, │ A, │ anyOf: [{ │\\\n│ B │ B │ type: 'number', │\\\n│ } │ } │ const: 0 │\\\n│ │ │ }, { │\\\n│ const T = Type.Enum(Foo) │ type T = Foo │ type: 'number', │\\\n│ │ │ const: 1 │\\\n│ │ │ }] │\n│ │ │ } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Const({ │ type T = { │ const T = { │\n│ x: 1, │ readonly x: 1, │ type: 'object', │\n│ y: 2, │ readonly y: 2 │ required: ['x', 'y'], │\n│ } as const) │ } │ properties: { │\n│ │ │ x: { │\n│ │ │ type: 'number', │\n│ │ │ const: 1 │\n│ │ │ }, │\n│ │ │ y: { │\n│ │ │ type: 'number', │\n│ │ │ const: 2 │\n│ │ │ } │\n│ │ │ } │\n│ │ │ } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.KeyOf( │ type T = keyof { │ const T = { │\n│ Type.Object({ │ x: number, │ anyOf: [{ │\\\n│ x: Type.Number(), │ y: number │ type: 'string', │\\\n│ y: Type.Number() │ } │ const: 'x' │\\\n│ }) │ │ }, { │\\\n│ ) │ │ type: 'string', │\\\n│ │ │ const: 'y' │\\\n│ │ │ }] │\n│ │ │ } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Union([ │ type T = string | number │ const T = { │\\\n│ Type.String(), │ │ anyOf: [{ │\\\n│ Type.Number() │ │ type: 'string' │\\\n│ ]) │ │ }, { │\\\n│ │ │ type: 'number' │\\\n│ │ │ }] │\n│ │ │ } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Intersect([ │ type T = { │ const T = { │\\\n│ Type.Object({ │ x: number │ allOf: [{ │\\\n│ x: Type.Number() │ } & { │ type: 'object', │\\\n│ }), │ y: number │ required: ['x'], │\\\n│ Type.Object({ │ } │ properties: { │\\\n│ y: Type.Number() │ │ x: { │\\\n│ }) │ │ type: 'number' │\\\n│ ]) │ │ } │\\\n│ │ │ } │\\\n│ │ │ }, { │\\\n│ │ │ type: 'object', |\\\n│ │ │ required: ['y'], │\\\n│ │ │ properties: { │\\\n│ │ │ y: { │\\\n│ │ │ type: 'number' │\\\n│ │ │ } │\\\n│ │ │ } │\\\n│ │ │ }] │\n│ │ │ } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Composite([ │ type T = { │ const T = { │\\\n│ Type.Object({ │ x: number, │ type: 'object', │\\\n│ x: Type.Number() │ y: number │ required: ['x', 'y'], │\\\n│ }), │ } │ properties: { │\\\n│ Type.Object({ │ │ x: { │\\\n│ y: Type.Number() │ │ type: 'number' │\\\n│ }) │ │ }, │\\\n│ ]) │ │ y: { │\n│ │ │ type: 'number' │\n│ │ │ } │\n│ │ │ } │\n│ │ │ } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Never() │ type T = never │ const T = { │\n│ │ │ not: {} │\n│ │ │ } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Not( | type T = unknown │ const T = { │\n│ Type.String() │ │ not: { │\n│ ) │ │ type: 'string' │\n│ │ │ } │\n│ │ │ } │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Extends( │ type T = │ const T = { │\n│ Type.String(), │ string extends number │ const: false, │\n│ Type.Number(), │ ? true │ type: 'boolean' │\n│ Type.Literal(true), │ : false │ } │\n│ Type.Literal(false) │ │ │\n│ ) │ │ │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Extract( │ type T = Extract< │ const T = { │\n│ Type.Union([ │ string | number, │ type: 'string' │\\\n│ Type.String(), │ string │ } │\\\n│ Type.Number(), │ > │ │\\\n│ ]), │ │ │\n│ Type.String() │ │ │\n│ ) │ │ │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Exclude( │ type T = Exclude< │ const T = { │\n│ Type.Union([ │ string | number, │ type: 'number' │\\\n│ Type.String(), │ string │ } │\\\n│ Type.Number(), │ > │ │\\\n│ ]), │ │ │\n│ Type.String() │ │ │\n│ ) │ │ │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Mapped( │ type T = { │ const T = { │\n│ Type.Union([ │ [_ in 'x' | 'y'] : number │ type: 'object', │\\\n│ Type.Literal('x'), │ } │ required: ['x', 'y'], │\\\n│ Type.Literal('y') │ │ properties: { │\\\n│ ]), │ │ x: { │\n│ () => Type.Number() │ │ type: 'number' │\n│ ) │ │ }, │\n│ │ │ y: { │\n│ │ │ type: 'number' │\n│ │ │ } │\n│ │ │ } │\n│ │ │ } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const U = Type.Union([ │ type U = 'open' | 'close' │ const T = { │\\\n│ Type.Literal('open'), │ │ type: 'string', │\\\n│ Type.Literal('close') │ type T = `on${U}` │ pattern: '^on(open|close)$' │\\\n│ ]) │ │ } │\n│ │ │ │\n│ const T = Type │ │ │\n│ .TemplateLiteral([ │ │ │\\\n│ Type.Literal('on'), │ │ │\\\n│ U │ │ │\\\n│ ]) │ │ │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Record( │ type T = Record< │ const T = { │\n│ Type.String(), │ string, │ type: 'object', │\n│ Type.Number() │ number │ patternProperties: { │\n│ ) │ > │ '^.*$': { │\n│ │ │ type: 'number' │\n│ │ │ } │\n│ │ │ } │\n│ │ │ } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Partial( │ type T = Partial<{ │ const T = { │\n│ Type.Object({ │ x: number, │ type: 'object', │\n│ x: Type.Number(), │ y: number │ properties: { │\n│ y: Type.Number() | }> │ x: { │\n│ }) │ │ type: 'number' │\n│ ) │ │ }, │\n│ │ │ y: { │\n│ │ │ type: 'number' │\n│ │ │ } │\n│ │ │ } │\n│ │ │ } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Required( │ type T = Required<{ │ const T = { │\n│ Type.Object({ │ x?: number, │ type: 'object', │\n│ x: Type.Optional( │ y?: number │ required: ['x', 'y'], │\n│ Type.Number() | }> │ properties: { │\n│ ), │ │ x: { │\n│ y: Type.Optional( │ │ type: 'number' │\n│ Type.Number() │ │ }, │\n│ ) │ │ y: { │\n│ }) │ │ type: 'number' │\n│ ) │ │ } │\n│ │ │ } │\n│ │ │ } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Pick( │ type T = Pick<{ │ const T = { │\n│ Type.Object({ │ x: number, │ type: 'object', │\n│ x: Type.Number(), │ y: number │ required: ['x'], │\n│ y: Type.Number() │ }, 'x'> │ properties: { │\n│ }), ['x'] | │ x: { │\n│ ) │ │ type: 'number' │\n│ │ │ } │\n│ │ │ } │\n│ │ │ } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Omit( │ type T = Omit<{ │ const T = { │\n│ Type.Object({ │ x: number, │ type: 'object', │\n│ x: Type.Number(), │ y: number │ required: ['y'], │\n│ y: Type.Number() │ }, 'x'> │ properties: { │\n│ }), ['x'] | │ y: { │\n│ ) │ │ type: 'number' │\n│ │ │ } │\n│ │ │ } │\n│ │ │ } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Index( │ type T = { │ const T = { │\n│ Type.Object({ │ x: number, │ type: 'number' │\n│ x: Type.Number(), │ y: string │ } │\n│ y: Type.String() │ }['x'] │ │\n│ }), ['x'] │ │ │\n│ ) │ │ │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const A = Type.Tuple([ │ type A = [0, 1] │ const T = { │\\\n│ Type.Literal(0), │ type B = [2, 3] │ type: 'array', │\\\n│ Type.Literal(1) │ type T = [ │ items: [ │\\\n│ ]) │ ...A, │ { const: 0 }, │\\\n│ const B = Type.Tuple([ │ ...B │ { const: 1 }, │\\\n| Type.Literal(2), │ ] │ { const: 2 }, │\\\n| Type.Literal(3) │ │ { const: 3 } │\\\n│ ]) │ │ ], │\n│ const T = Type.Tuple([ │ │ additionalItems: false, │\\\n| ...Type.Rest(A), │ │ minItems: 4, │\\\n| ...Type.Rest(B) │ │ maxItems: 4 │\\\n│ ]) │ │ } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Uncapitalize( │ type T = Uncapitalize< │ const T = { │\n│ Type.Literal('Hello') │ 'Hello' │ type: 'string', │\n│ ) │ > │ const: 'hello' │\n│ │ │ } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Capitalize( │ type T = Capitalize< │ const T = { │\n│ Type.Literal('hello') │ 'hello' │ type: 'string', │\n│ ) │ > │ const: 'Hello' │\n│ │ │ } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Uppercase( │ type T = Uppercase< │ const T = { │\n│ Type.Literal('hello') │ 'hello' │ type: 'string', │\n│ ) │ > │ const: 'HELLO' │\n│ │ │ } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Lowercase( │ type T = Lowercase< │ const T = { │\n│ Type.Literal('HELLO') │ 'HELLO' │ type: 'string', │\n│ ) │ > │ const: 'hello' │\n│ │ │ } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const R = Type.Ref('T') │ type R = unknown │ const R = { $ref: 'T' } │\n│ │ │ │\n└────────────────────────────────┴─────────────────────────────┴────────────────────────────────┘\n```\n\n### JavaScript Types\n\n[Permalink: JavaScript Types](https://www.npmjs.com/package/@sinclair/typebox#javascript-types)\n\nTypeBox provides an extended type set that can be used to create schematics for common JavaScript constructs. These types can not be used with any standard Json Schema validator; but can be used to frame schematics for interfaces that may receive Json validated data. JavaScript types are prefixed with the `[JavaScript]` JSDoc comment for convenience. The following table lists the supported types.\n\n```\n┌────────────────────────────────┬─────────────────────────────┬────────────────────────────────┐\n│ TypeBox │ TypeScript │ Extended Schema │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Constructor([ │ type T = new ( │ const T = { │\\\n│ Type.String(), │ arg0: string, │ type: 'Constructor', │\\\n│ Type.Number() │ arg0: number │ parameters: [{ │\\\n│ ], Type.Boolean()) │ ) => boolean │ type: 'string' │\\\n│ │ │ }, { │\\\n│ │ │ type: 'number' │\\\n│ │ │ }], │\n│ │ │ returns: { │\n│ │ │ type: 'boolean' │\n│ │ │ } │\n│ │ │ } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Function([ │ type T = ( │ const T = { │\\\n| Type.String(), │ arg0: string, │ type: 'Function', │\\\n│ Type.Number() │ arg1: number │ parameters: [{ │\\\n│ ], Type.Boolean()) │ ) => boolean │ type: 'string' │\\\n│ │ │ }, { │\\\n│ │ │ type: 'number' │\\\n│ │ │ }], │\n│ │ │ returns: { │\n│ │ │ type: 'boolean' │\n│ │ │ } │\n│ │ │ } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Promise( │ type T = Promise<string> │ const T = { │\n│ Type.String() │ │ type: 'Promise', │\n│ ) │ │ item: { │\n│ │ │ type: 'string' │\n│ │ │ } │\n│ │ │ } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = │ type T = │ const T = { │\n│ Type.AsyncIterator( │ AsyncIterableIterator< │ type: 'AsyncIterator', │\n│ Type.String() │ string │ items: { │\n│ ) │ > │ type: 'string' │\n│ │ │ } │\n│ │ │ } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Iterator( │ type T = │ const T = { │\n│ Type.String() │ IterableIterator<string> │ type: 'Iterator', │\n│ ) │ │ items: { │\n│ │ │ type: 'string' │\n│ │ │ } │\n│ │ │ } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.RegExp(/abc/i) │ type T = string │ const T = { │\n│ │ │ type: 'RegExp' │\n│ │ │ source: 'abc' │\n│ │ │ flags: 'i' │\n│ │ │ } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Uint8Array() │ type T = Uint8Array │ const T = { │\n│ │ │ type: 'Uint8Array' │\n│ │ │ } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Date() │ type T = Date │ const T = { │\n│ │ │ type: 'Date' │\n│ │ │ } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Undefined() │ type T = undefined │ const T = { │\n│ │ │ type: 'undefined' │\n│ │ │ } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Symbol() │ type T = symbol │ const T = { │\n│ │ │ type: 'symbol' │\n│ │ │ } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.BigInt() │ type T = bigint │ const T = { │\n│ │ │ type: 'bigint' │\n│ │ │ } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Void() │ type T = void │ const T = { │\n│ │ │ type: 'void' │\n│ │ │ } │\n│ │ │ │\n└────────────────────────────────┴─────────────────────────────┴────────────────────────────────┘\n```\n\n### Options\n\n[Permalink: Options](https://www.npmjs.com/package/@sinclair/typebox#options)\n\nYou can pass Json Schema options on the last argument of any given type. Option hints specific to each type are provided for convenience.\n\n```\n// String must be an email\nconst T = Type.String({ // const T = {\n format: 'email' // type: 'string',\n}) // format: 'email'\n // }\n\n// Number must be a multiple of 2\nconst T = Type.Number({ // const T = {\n multipleOf: 2 // type: 'number',\n}) // multipleOf: 2\n // }\n\n// Array must have at least 5 integer values\nconst T = Type.Array(Type.Integer(), { // const T = {\n minItems: 5 // type: 'array',\n}) // minItems: 5,\n // items: {\n // type: 'integer'\n // }\n // }\n```\n\n### Properties\n\n[Permalink: Properties](https://www.npmjs.com/package/@sinclair/typebox#properties)\n\nObject properties can be modified with Readonly and Optional. The following table shows how these modifiers map between TypeScript and Json Schema.\n\n```\n┌────────────────────────────────┬─────────────────────────────┬────────────────────────────────┐\n│ TypeBox │ TypeScript │ Json Schema │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Object({ │ type T = { │ const T = { │\n│ name: Type.ReadonlyOptional( │ readonly name?: string │ type: 'object', │\n│ Type.String() │ } │ properties: { │\n│ ) │ │ name: { │\n│ }) \t │ │ type: 'string' │\n│ │ │ } │\n│ │ │ } │\n│ │ │ } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Object({ │ type T = { │ const T = { │\n│ name: Type.Readonly( │ readonly name: string │ type: 'object', │\n│ Type.String() │ } │ properties: { │\n│ ) │ │ name: { │\n│ }) \t │ │ type: 'string' │\n│ │ │ } │\n│ │ │ }, │\n│ │ │ required: ['name'] │\n│ │ │ } │\n│ │ │ │\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\n│ const T = Type.Object({ │ type T = { │ const T = { │\n│ name: Type.Optional( │ name?: string │ type: 'object', │\n│ Type.String() │ } │ properties: { │\n│ ) │ │ name: { │\n│ }) \t │ │ type: 'string' │\n│ │ │ } │\n│ │ │ } │\n│ │ │ } │\n│ │ │ │\n└────────────────────────────────┴─────────────────────────────┴────────────────────────────────┘\n```\n\n### Generic Types\n\n[Permalink: Generic Types](https://www.npmjs.com/package/@sinclair/typebox#generic-types)\n\nGeneric types can be created with generic functions.\n\n```\nconst Nullable = <T extends TSchema>(T: T) => { // type Nullable<T> = T | null\n return Type.Union([T, Type.Null()])\n}\n\nconst T = Nullable(Type.String()) // type T = Nullable<string>\n```\n\n### Recursive Types\n\n[Permalink: Recursive Types](https://www.npmjs.com/package/@sinclair/typebox#recursive-types)\n\nUse the Recursive function to create recursive types.\n\n```\nconst Node = Type.Recursive(This => Type.Object({ // const Node = {\n id: Type.String(), // $id: 'Node',\n nodes: Type.Array(This) // type: 'object',\n}), { $id: 'Node' }) // properties: {\n // id: {\n // type: 'string'\n // },\n // nodes: {\n // type: 'array',\n // items: {\n // $ref: 'Node'\n // }\n // }\n // },\n // required: [\\\n // 'id',\\\n // 'nodes'\\\n // ]\n // }\n\ntype Node = Static<typeof Node> // type Node = {\n // id: string\n // nodes: Node[]\n // }\n\nfunction test(node: Node) {\n const id = node.nodes[0].nodes[0].id // id is string\n}\n```\n\n### Module Types\n\n[Permalink: Module Types](https://www.npmjs.com/package/@sinclair/typebox#module-types)\n\nModule types are containers for a set of referential types. Modules act as namespaces, enabling types to reference one another via string identifiers. Modules support both singular and mutually recursive references, as well as deferred dereferencing for computed types such as Partial. Types imported from a module are expressed using the Json Schema `$defs` keyword.\n\n```\nconst Module = Type.Module({\n PartialUser: Type.Partial(Type.Ref('User')), // TComputed<'Partial', [TRef<'User'>]>\n\n User: Type.Object({ // TObject<{\n id: Type.String(), // user: TString,\n name: Type.String(), // name: TString,\n email: Type.String() // email: TString\n }), // }>\n})\nconst User = Module.Import('User') // const User: TImport<{...}, 'User'>\n\ntype User = Static<typeof User> // type User = {\n // id: string,\n // name: string,\n // email: string\n // }\n\nconst PartialUser = Module.Import('PartialUser') // const PartialUser: TImport<{...}, 'PartialUser'>\n\ntype PartialUser = Static<typeof PartialUser> // type PartialUser = {\n // id?: string,\n // name?: string,\n // email?: string\n // }\n```\n\n### Template Literal Types\n\n[Permalink: Template Literal Types](https://www.npmjs.com/package/@sinclair/typebox#template-literal-types)\n\nTypeBox supports template literal types with the TemplateLiteral function. This type can be created using a syntax similar to the TypeScript template literal syntax or composed from exterior types. TypeBox encodes template literals as regular expressions which enables the template to be checked by Json Schema validators. This type also supports regular expression parsing that enables template patterns to be used for generative types. The following shows both TypeScript and TypeBox usage.\n\n```\n// TypeScript\n\ntype K = `prop${'A'|'B'|'C'}` // type T = 'propA' | 'propB' | 'propC'\n\ntype R = Record<K, string> // type R = {\n // propA: string\n // propB: string\n // propC: string\n // }\n\n// TypeBox\n\nconst K = Type.TemplateLiteral('prop${A|B|C}') // const K: TTemplateLiteral<[\\\n // TLiteral<'prop'>,\\\n // TUnion<[\\\n // TLiteral<'A'>,\\\n // TLiteral<'B'>,\\\n // TLiteral<'C'>,\\\n // ]>\\\n // ]>\n\nconst R = Type.Record(K, Type.String()) // const R: TObject<{\n // propA: TString,\n // propB: TString,\n // propC: TString,\n // }>\n```\n\n### Indexed Access Types\n\n[Permalink: Indexed Access Types](https://www.npmjs.com/package/@sinclair/typebox#indexed-access-types)\n\nTypeBox supports indexed access types with the Index function. This function enables uniform access to interior property and element types without having to extract them from the underlying schema representation. Index types are supported for Object, Array, Tuple, Union and Intersect types.\n\n```\nconst T = Type.Object({ // type T = {\n x: Type.Number(), // x: number,\n y: Type.String(), // y: string,\n z: Type.Boolean() // z: boolean\n}) // }\n\nconst A = Type.Index(T, ['x']) // type A = T['x']\n //\n // ... evaluated as\n //\n // const A: TNumber\n\nconst B = Type.Index(T, ['x', 'y']) // type B = T['x' | 'y']\n //\n // ... evaluated as\n //\n // const B: TUnion<[\\\n // TNumber,\\\n // TString,\\\n // ]>\n\nconst C = Type.Index(T, Type.KeyOf(T)) // type C = T[keyof T]\n //\n // ... evaluated as\n //\n // const C: TUnion<[\\\n // TNumber,\\\n // TString,\\\n // TBoolean\\\n // ]>\n```\n\n### Mapped Types\n\n[Permalink: Mapped Types](https://www.npmjs.com/package/@sinclair/typebox#mapped-types)\n\nTypeBox supports mapped types with the Mapped function. This function accepts two arguments, the first is a union type typically derived from KeyOf, the second is a mapping function that receives a mapping key `K` that can be used to index properties of a type. The following implements a mapped type that remaps each property to be `T | null`.\n\n```\nconst T = Type.Object({ // type T = {\n x: Type.Number(), // x: number,\n y: Type.String(), // y: string,\n z: Type.Boolean() // z: boolean\n}) // }\n\nconst M = Type.Mapped(Type.KeyOf(T), K => { // type M = { [K in keyof T]: T[K] | null }\n return Type.Union([Type.Index(T, K), Type.Null()]) //\n}) // ... evaluated as\n //\n // const M: TObject<{\n // x: TUnion<[TNumber, TNull]>,\n // y: TUnion<[TString, TNull]>,\n // z: TUnion<[TBoolean, TNull]>\n // }>\n```\n\n### Conditional Types\n\n[Permalink: Conditional Types](https://www.npmjs.com/package/@sinclair/typebox#conditional-types)\n\nTypeBox supports runtime conditional types with the Extends function. This function performs a structural assignability check against the first (`left`) and second (`right`) arguments and will return either the third (`true`) or fourth (`false`) argument based on the result. The conditional types Exclude and Extract are also supported. The following shows both TypeScript and TypeBox examples of conditional types.\n\n```\n// Extends\nconst A = Type.Extends( // type A = string extends number ? 1 : 2\n Type.String(), //\n Type.Number(), // ... evaluated as\n Type.Literal(1), //\n Type.Literal(2) // const A: TLiteral<2>\n)\n\n// Extract\nconst B = Type.Extract( // type B = Extract<1 | 2 | 3, 1>\n Type.Union([ //\\\n Type.Literal(1), // ... evaluated as\\\n Type.Literal(2), //\\\n Type.Literal(3) // const B: TLiteral<1>\\\n ]),\n Type.Literal(1)\n)\n\n// Exclude\nconst C = Type.Exclude( // type C = Exclude<1 | 2 | 3, 1>\n Type.Union([ //\\\n Type.Literal(1), // ... evaluated as\\\n Type.Literal(2), //\\\n Type.Literal(3) // const C: TUnion<[\\\n ]), // TLiteral<2>,\\\n Type.Literal(1) // TLiteral<3>,\\\n) // ]>\n```\n\n### Transform Types\n\n[Permalink: Transform Types](https://www.npmjs.com/package/@sinclair/typebox#transform-types)\n\nTypeBox supports value decoding and encoding with Transform types. These types work in tandem with the Encode and Decode functions available on the Value and TypeCompiler submodules. Transform types can be used to convert Json encoded values into constructs more natural to JavaScript. The following creates a Transform type to decode numbers into Dates using the Value submodule.\n\n```\nimport { Value } from '@sinclair/typebox/value'\n\nconst T = Type.Transform(Type.Number())\n .Decode(value => new Date(value)) // decode: number to Date\n .Encode(value => value.getTime()) // encode: Date to number\n\nconst D = Value.Decode(T, 0) // const D = Date(1970-01-01T00:00:00.000Z)\nconst E = Value.Encode(T, D) // const E = 0\n```\n\nUse the StaticEncode or StaticDecode types to infer a Transform type.\n\n```\nimport { Static, StaticDecode, StaticEncode } from '@sinclair/typebox'\n\nconst T = Type.Transform(Type.Array(Type.Number(), { uniqueItems: true }))\n .Decode(value => new Set(value))\n .Encode(value => [...value])\n\ntype D = StaticDecode<typeof T> // type D = Set<number>\ntype E = StaticEncode<typeof T> // type E = Array<number>\ntype T = Static<typeof T> // type T = Array<number>\n```\n\n### Unsafe Types\n\n[Permalink: Unsafe Types](https://www.npmjs.com/package/@sinclair/typebox#unsafe-types)\n\nTypeBox supports user defined types with Unsafe. This type allows you to specify both schema representation and inference type. The following creates an Unsafe type with a number schema that infers as string.\n\n```\nconst T = Type.Unsafe<string>({ type: 'number' }) // const T = { type: 'number' }\n\ntype T = Static<typeof T> // type T = string - ?\n```\n\nThe Unsafe type is often used to create schematics for extended specifications like OpenAPI.\n\n```\nconst Nullable = <T extends TSchema>(schema: T) => Type.Unsafe<Static<T> | null>({\n ...schema, nullable: true\n})\n\nconst T = Nullable(Type.String()) // const T = {\n // type: 'string',\n // nullable: true\n // }\n\ntype T = Static<typeof T> // type T = string | null\n\nconst StringEnum = <T extends string[]>(values: [...T]) => Type.Unsafe<T[number]>({\n type: 'string', enum: values\n})\nconst S = StringEnum(['A', 'B', 'C']) // const S = {\n // enum: ['A', 'B', 'C']\n // }\n\ntype S = Static<typeof T> // type S = 'A' | 'B' | 'C'\n```\n\n### TypeGuard\n\n[Permalink: TypeGuard](https://www.npmjs.com/package/@sinclair/typebox#typeguard)\n\nTypeBox can check its own types with the TypeGuard module. This module is written for type introspection and provides structural tests for every built-in TypeBox type. Functions of this module return `is` guards which can be used with control flow assertions to obtain schema inference for unknown values. The following guards that the value `T` is TString.\n\n```\nimport { TypeGuard, Kind } from '@sinclair/typebox'\n\nconst T = { [Kind]: 'String', type: 'string' }\n\nif(TypeGuard.IsString(T)) {\n\n // T is TString\n}\n```\n\n## Values\n\n[Permalink: Values](https://www.npmjs.com/package/@sinclair/typebox#values)\n\nTypeBox provides an optional Value submodule that can be used to perform structural operations on JavaScript values. This submodule includes functionality to create, check and cast values from types as well as check equality, clone, diff and patch JavaScript values. This submodule is provided via optional import.\n\n```\nimport { Value } from '@sinclair/typebox/value'\n```\n\n### Assert\n\n[Permalink: Assert](https://www.npmjs.com/package/@sinclair/typebox#assert)\n\nUse the Assert function to assert a value is valid.\n\n```\nlet value: unknown = 1\n\nValue.Assert(Type.Number(), value) // throws AssertError if invalid\n```\n\n### Create\n\n[Permalink: Create](https://www.npmjs.com/package/@sinclair/typebox#create)\n\nUse the Create function to create a value from a type. TypeBox will use default values if specified.\n\n```\nconst T = Type.Object({ x: Type.Number(), y: Type.Number({ default: 42 }) })\n\nconst A = Value.Create(T) // const A = { x: 0, y: 42 }\n```\n\n### Clone\n\n[Permalink: Clone](https://www.npmjs.com/package/@sinclair/typebox#clone)\n\nUse the Clone function to deeply clone a value.\n\n```\nconst A = Value.Clone({ x: 1, y: 2, z: 3 }) // const A = { x: 1, y: 2, z: 3 }\n```\n\n### Check\n\n[Permalink: Check](https://www.npmjs.com/package/@sinclair/typebox#check)\n\nUse the Check function to type check a value.\n\n```\nconst T = Type.Object({ x: Type.Number() })\n\nconst R = Value.Check(T, { x: 1 }) // const R = true\n```\n\n### Convert\n\n[Permalink: Convert](https://www.npmjs.com/package/@sinclair/typebox#convert)\n\nUse the Convert function to convert a value into its target type if a reasonable conversion is possible. This function may return an invalid value and should be checked before use. Its return type is `unknown`.\n\n```\nconst T = Type.Object({ x: Type.Number() })\n\nconst R1 = Value.Convert(T, { x: '3.14' }) // const R1 = { x: 3.14 }\n\nconst R2 = Value.Convert(T, { x: 'not a number' }) // const R2 = { x: 'not a number' }\n```\n\n### Clean\n\n[Permalink: Clean](https://www.npmjs.com/package/@sinclair/typebox#clean)\n\nUse Clean to remove excess properties from a value. This function does not check the value and returns an unknown type. You should Check the result before use. Clean is a mutable operation. To avoid mutation, Clone the value first.\n\n```\nconst T = Type.Object({\n x: Type.Number(),\n y: Type.Number()\n})\n\nconst X = Value.Clean(T, null) // const 'X = null\n\nconst Y = Value.Clean(T, { x: 1 }) // const 'Y = { x: 1 }\n\nconst Z = Value.Clean(T, { x: 1, y: 2, z: 3 }) // const 'Z = { x: 1, y: 2 }\n```\n\n### Default\n\n[Permalink: Default](https://www.npmjs.com/package/@sinclair/typebox#default)\n\nUse Default to generate missing properties on a value using default schema annotations if available. This function does not check the value and returns an unknown type. You should Check the result before use. Default is a mutable operation. To avoid mutation, Clone the value first.\n\n```\nconst T = Type.Object({\n x: Type.Number({ default: 0 }),\n y: Type.Number({ default: 0 })\n})\n\nconst X = Value.Default(T, null) // const 'X = null - non-enumerable\n\nconst Y = Value.Default(T, { }) // const 'Y = { x: 0, y: 0 }\n\nconst Z = Value.Default(T, { x: 1 }) // const 'Z = { x: 1, y: 0 }\n```\n\n### Cast\n\n[Permalink: Cast](https://www.npmjs.com/package/@sinclair/typebox#cast)\n\nUse the Cast function to upcast a value into a target type. This function will retain as much information as possible from the original value. The Cast function is intended to be used in data migration scenarios where existing values need to be upgraded to match a modified type.\n\n```\nconst T = Type.Object({ x: Type.Number(), y: Type.Number() }, { additionalProperties: false })\n\nconst X = Value.Cast(T, null) // const X = { x: 0, y: 0 }\n\nconst Y = Value.Cast(T, { x: 1 }) // const Y = { x: 1, y: 0 }\n\nconst Z = Value.Cast(T, { x: 1, y: 2, z: 3 }) // const Z = { x: 1, y: 2 }\n```\n\n### Decode\n\n[Permalink: Decode](https://www.npmjs.com/package/@sinclair/typebox#decode)\n\nUse the Decode function to decode a value from a type or throw if the value is invalid. The return value will infer as the decoded type. This function will run Transform codecs if available.\n\n```\nconst A = Value.Decode(Type.String(), 'hello') // const A = 'hello'\n\nconst B = Value.Decode(Type.String(), 42) // throw\n```\n\n### Encode\n\n[Permalink: Encode](https://www.npmjs.com/package/@sinclair/typebox#encode)\n\nUse the Encode function to encode a value to a type or throw if the value is invalid. The return value will infer as the encoded type. This function will run Transform codecs if available.\n\n```\nconst A = Value.Encode(Type.String(), 'hello') // const A = 'hello'\n\nconst B = Value.Encode(Type.String(), 42) // throw\n```\n\n### Parse\n\n[Permalink: Parse](https://www.npmjs.com/package/@sinclair/typebox#parse)\n\nUse the Parse function to parse a value. This function calls the `Clone``Clean`, `Default`, `Convert`, `Assert` and `Decode` Value functions in this exact order to process a value.\n\n```\nconst R = Value.Parse(Type.String(), 'hello') // const R: string = \"hello\"\n\nconst E = Value.Parse(Type.String(), undefined) // throws AssertError\n```\n\nYou can override the order in which functions are run, or omit functions entirely using the following.\n\n```\n// Runs no functions.\n\nconst R = Value.Parse([], Type.String(), 12345)\n\n// Runs the Assert() function.\n\nconst E = Value.Parse(['Assert'], Type.String(), 12345)\n\n// Runs the Convert() function followed by the Assert() function.\n\nconst S = Value.Parse(['Convert', 'Assert'], Type.String(), 12345)\n```\n\n### Equal\n\n[Permalink: Equal](https://www.npmjs.com/package/@sinclair/typebox#equal)\n\nUse the Equal function to deeply check for value equality.\n\n```\nconst R = Value.Equal( // const R = true\n { x: 1, y: 2, z: 3 },\n { x: 1, y: 2, z: 3 }\n)\n```\n\n### Hash\n\n[Permalink: Hash](https://www.npmjs.com/package/@sinclair/typebox#hash)\n\nUse the Hash function to create a [FNV1A-64](https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function) non-cryptographic hash of a value.\n\n```\nconst A = Value.Hash({ x: 1, y: 2, z: 3 }) // const A = 2910466848807138541n\n\nconst B = Value.Hash({ x: 1, y: 4, z: 3 }) // const B = 1418369778807423581n\n```\n\n### Diff\n\n[Permalink: Diff](https://www.npmjs.com/package/@sinclair/typebox#diff)\n\nUse the Diff function to generate a sequence of edits that will transform one value into another.\n\n```\nconst E = Value.Diff( // const E = [\\\n { x: 1, y: 2, z: 3 }, // { type: 'update', path: '/y', value: 4 },\\\n { y: 4, z: 5, w: 6 } // { type: 'update', path: '/z', value: 5 },\\\n) // { type: 'insert', path: '/w', value: 6 },\\\n // { type: 'delete', path: '/x' }\\\n // ]\n```\n\n### Patch\n\n[Permalink: Patch](https://www.npmjs.com/package/@sinclair/typebox#patch)\n\nUse the Patch function to apply a sequence of edits.\n\n```\nconst A = { x: 1, y: 2 }\n\nconst B = { x: 3 }\n\nconst E = Value.Diff(A, B) // const E = [\\\n // { type: 'update', path: '/x', value: 3 },\\\n // { type: 'delete', path: '/y' }\\\n // ]\n\nconst C = Value.Patch<typeof B>(A, E) // const C = { x: 3 }\n```\n\n### Errors\n\n[Permalink: Errors](https://www.npmjs.com/package/@sinclair/typebox#errors)\n\nUse the Errors function to enumerate validation errors.\n\n```\nconst T = Type.Object({ x: Type.Number(), y: Type.Number() })\n\nconst R = [...Value.Errors(T, { x: '42' })] // const R = [{\\\n // schema: { type: 'number' },\\\n // path: '/x',\\\n // value: '42',\\\n // message: 'Expected number'\\\n // }, {\\\n // schema: { type: 'number' },\\\n // path: '/y',\\\n // value: undefined,\\\n // message: 'Expected number'\\\n // }]\n```\n\n### Mutate\n\n[Permalink: Mutate](https://www.npmjs.com/package/@sinclair/typebox#mutate)\n\nUse the Mutate function to perform a deep mutable value assignment while retaining internal references.\n\n```\nconst Y = { z: 1 } // const Y = { z: 1 }\nconst X = { y: Y } // const X = { y: { z: 1 } }\nconst A = { x: X } // const A = { x: { y: { z: 1 } } }\n\nValue.Mutate(A, { x: { y: { z: 2 } } }) // A' = { x: { y: { z: 2 } } }\n\nconst R0 = A.x.y.z === 2 // const R0 = true\nconst R1 = A.x.y === Y // const R1 = true\nconst R2 = A.x === X // const R2 = true\n```\n\n### Pointer\n\n[Permalink: Pointer](https://www.npmjs.com/package/@sinclair/typebox#pointer)\n\nUse ValuePointer to perform mutable updates on existing values using [RFC6901](https://www.rfc-editor.org/rfc/rfc6901) Json Pointers.\n\n```\nimport { ValuePointer } from '@sinclair/typebox/value'\n\nconst A = { x: 0, y: 0, z: 0 }\n\nValuePointer.Set(A, '/x', 1) // A' = { x: 1, y: 0, z: 0 }\nValuePointer.Set(A, '/y', 1) // A' = { x: 1, y: 1, z: 0 }\nValuePointer.Set(A, '/z', 1) // A' = { x: 1, y: 1, z: 1 }\n```\n\n## Syntax Types\n\n[Permalink: Syntax Types](https://www.npmjs.com/package/@sinclair/typebox#syntax-types)\n\nTypeBox provides experimental support for parsing TypeScript annotation syntax into TypeBox types.\n\nThis feature is provided via optional import.\n\n```\nimport { Syntax } from '@sinclair/typebox/syntax'\n```\n\n### Create\n\n[Permalink: Create](https://www.npmjs.com/package/@sinclair/typebox#create-1)\n\nUse the Syntax function to create TypeBox types from TypeScript syntax ( [Example](https://www.typescriptlang.org/play/?moduleResolution=99&module=199&ts=5.8.0-beta#code/JYWwDg9gTgLgBAbzgZQJ4DsYEMAecC+cAZlBCHAOQACAzsOgMYA2WwUA9DKmAKYBGEHOxoZsOCgChQkWIhTYYwBgWKly1OoxZtO3foMkSGEdDXgAVOAF4Uo3AAoABkhwAuOOgCuIPjygAaOFR3Lx8-AkcASjgY2Jj2djhjUwt3cwB5PgArHgYYAB4ECTiS0rLyisrYhNi3OHMAOW9fAOKq9o7OuBqY4PqmsKg2rpHR+MT8AD4JCS5eeut5LEUGfLmeCCJ6ybHKmvWFmyLdk86euDrQlv9h07uy876rv1v7t-GCIA))\n\n```\nconst T = Syntax(`{ x: number, y: number }`) // const T: TObject<{\n // x: TNumber,\n // y: TNumber\n // }>\n\ntype T = Static<typeof T> // type T = {\n // x: number,\n // y: number\n // }\n```\n\n### Parameters\n\n[Permalink: Parameters](https://www.npmjs.com/package/@sinclair/typebox#parameters)\n\nSyntax types can be parameterized to receive exterior types ( [Example](https://www.typescriptlang.org/play/?moduleResolution=99&module=199&ts=5.8.0-beta#code/JYWwDg9gTgLgBAbzgZQJ4DsYEMAecC+cAZlBCHAOQACAzsOgMYA2WwUA9DKmAKYBGEHOxoZsOCgCgJDCOhrwAKnAC8KUbgAUAAyQ4AXHHQBXEHx5QANHFQHjp8wS0BKOK7ev27ODLmKDCgHk+ACseBhgAHgQJd1i4+ITEpLdPN304BQA5EzNLGOSCwqK4VNcbDOz7KHzi2rqPL3wAPikfeRQVNUxNJCV8Ky0ABSxYYCwmCIUm52LUtvhkfyDQ8Kia+o2C0rh0wLAYYFlxycrcpot1zav47fK9g6OJrJzzFuv3m8amoA))\n\n```\nconst T = Syntax(`{ x: number, y: number }`) // const T: TObject<{\n // x: TNumber,\n // y: TNumber\n // }>\n\nconst S = Syntax({ T }, `Partial<T>`) // const S: TObject<{\n // x: TOptional<TNumber>,\n // y: TOptional<TNumber>\n // }>\n```\n\n### Generics\n\n[Permalink: Generics](https://www.npmjs.com/package/@sinclair/typebox#generics)\n\nSyntax types support generic parameters in the following way ( [Example](https://www.typescriptlang.org/play/?moduleResolution=99&module=199&ts=5.8.0-beta#code/JYWwDg9gTgLgBAbzgZQJ4DsYEMAecC+cAZlBCHAOQACAzsOgMYA2WwUA9DKmAKYBGEHOxoZsOCgChQkWIhTYYwBgWKly1OoxZtO3foMkSGEdDXgA1HgxjQ4AXhSjcACgAGAHgAaAGjgBNXwAtAD45CTg4HAAuOB84cLhUGID4iIAvGMD4-FcASgkjEzM4ACEsOhpLa2gae0dMFyQqmygCX1cEBOi4Zuh3AEZfAAZh4O8EpJ6rFvcRuEG4IbGEjKnqqFnh337lnPyJLl5S8uBK6Zq65AUld0OeCCJjit6oGlCIiPZ2ODun05fag5Oh8QaCweCIZCoV8Pt0kN0FpM5qshm0ElCMZisSCYRFJvCYnNJgsUWjseSKeDcXBVgTFr4kb5Vv0COjKezsTD8EA))\n\n```\nconst Vector = Syntax(`<X, Y, Z> {\n x: X,\n y: Y,\n z: Z\n}`)\n\nconst BasisVectors = Syntax({ Vector }, `{\n x: Vector<1, 0, 0>,\n y: Vector<0, 1, 0>,\n z: Vector<0, 0, 1>,\n}`)\n\ntype BasisVectors = Static<typeof BasisVectors> // type BasisVectors = {\n // x: { x: 1, y: 0, z: 0 },\n // y: { x: 0, y: 1, z: 0 },\n // z: { x: 0, y: 0, z: 1 }\n // }\n```\n\n### Options\n\n[Permalink: Options](https://www.npmjs.com/package/@sinclair/typebox#options-1)\n\nOptions can be passed via the last parameter.\n\n```\nconst T = Syntax(`number`, { minimum: 42 }) // const T = {\n // type: 'number',\n // minimum: 42\n // }\n```\n\n### NoInfer\n\n[Permalink: NoInfer](https://www.npmjs.com/package/@sinclair/typebox#noinfer)\n\nSyntax parsing is an expensive type level operation and can impact on language service performance. Use the NoInfer function parse syntax at runtime only.\n\n```\nimport { NoInfer } from '@sinclair/typebox/syntax'\n\nconst T = NoInfer(`number | string`) // const T: TSchema = {\n // anyOf: [\\\n // { type: 'number' },\\\n // { type: 'string' }\\\n // ]\n // }\n```\n\n## TypeRegistry\n\n[Permalink: TypeRegistry](https://www.npmjs.com/package/@sinclair/typebox#typeregistry)\n\nThe TypeBox type system can be extended with additional types and formats using the TypeRegistry and FormatRegistry modules. These modules integrate deeply with TypeBox's internal type checking infrastructure and can be used to create application specific types, or register schematics for alternative specifications.\n\n### TypeRegistry\n\n[Permalink: TypeRegistry](https://www.npmjs.com/package/@sinclair/typebox#typeregistry-1)\n\nUse the TypeRegistry to register a type. The Kind must match the registered type name.\n\n```\nimport { TSchema, Kind, TypeRegistry } from '@sinclair/typebox'\n\nTypeRegistry.Set('Foo', (schema, value) => value === 'foo')\n\nconst Foo = { [Kind]: 'Foo' } as TSchema\n\nconst A = Value.Check(Foo, 'foo') // const A = true\n\nconst B = Value.Check(Foo, 'bar') // const B = false\n```\n\n### FormatRegistry\n\n[Permalink: FormatRegistry](https://www.npmjs.com/package/@sinclair/typebox#formatregistry)\n\nUse the FormatRegistry to register a string format.\n\n```\nimport { FormatRegistry } from '@sinclair/typebox'\n\nFormatRegistry.Set('foo', (value) => value === 'foo')\n\nconst T = Type.String({ format: 'foo' })\n\nconst A = Value.Check(T, 'foo') // const A = true\n\nconst B = Value.Check(T, 'bar') // const B = false\n```\n\n## TypeCheck\n\n[Permalink: TypeCheck](https://www.npmjs.com/package/@sinclair/typebox#typecheck)\n\nTypeBox types target Json Schema Draft 7 and are compatible with any validator that supports this specification. TypeBox also provides a built-in type checking compiler designed specifically for TypeBox types that offers high performance compilation and value checking.\n\nThe following sections detail using Ajv and the TypeBox compiler infrastructure.\n\n## Ajv\n\n[Permalink: Ajv](https://www.npmjs.com/package/@sinclair/typebox#ajv)\n\nThe following shows the recommended setup for Ajv.\n\n```\n$ npm install ajv ajv-formats --save\n```\n\n```\nimport { Type } from '@sinclair/typebox'\nimport addFormats from 'ajv-formats'\nimport Ajv from 'ajv'\n\nconst ajv = addFormats(new Ajv({}), [\\\n 'date-time',\\\n 'time',\\\n 'date',\\\n 'email',\\\n 'hostname',\\\n 'ipv4',\\\n 'ipv6',\\\n 'uri',\\\n 'uri-reference',\\\n 'uuid',\\\n 'uri-template',\\\n 'json-pointer',\\\n 'relative-json-pointer',\\\n 'regex'\\\n])\n\nconst validate = ajv.compile(Type.Object({\n x: Type.Number(),\n y: Type.Number(),\n z: Type.Number()\n}))\n\nconst R = validate({ x: 1, y: 2, z: 3 }) // const R = true\n```\n\n### TypeCompiler\n\n[Permalink: TypeCompiler](https://www.npmjs.com/package/@sinclair/typebox#typecompiler)\n\nThe TypeBox TypeCompiler is a high performance JIT validation compiler that transforms TypeBox types into optimized JavaScript validation routines. The compiler is tuned for fast compilation as well as fast value assertion. It is built to serve as a validation backend that can be integrated into larger applications. It can also be used for code generation.\n\nThe TypeCompiler is provided as an optional import.\n\n```\nimport { TypeCompiler } from '@sinclair/typebox/compiler'\n```\n\nUse the Compile function to JIT compile a type. Note that compilation is generally an expensive operation and should only be performed once per type during application start up. TypeBox does not cache previously compiled types, and applications are expected to hold references to each compiled type for the lifetime of the application.\n\n```\nconst C = TypeCompiler.Compile(Type.Object({ // const C: TypeCheck<TObject<{\n x: Type.Number(), // x: TNumber;\n y: Type.Number(), // y: TNumber;\n z: Type.Number() // z: TNumber;\n})) // }>>\n\nconst R = C.Check({ x: 1, y: 2, z: 3 }) // const R = true\n```\n\nUse the Errors function to generate diagnostic errors for a value. The Errors function will return an iterator that when enumerated; will perform an exhaustive check across the entire value yielding any error found. For performance, this function should only be called after a failed Check. Applications may also choose to yield only the first value to avoid exhaustive error generation.\n\n```\nconst C = TypeCompiler.Compile(Type.Object({ // const C: TypeCheck<TObject<{\n x: Type.Number(), // x: TNumber;\n y: Type.Number(), // y: TNumber;\n z: Type.Number() // z: TNumber;\n})) // }>>\n\nconst value = { }\n\nconst first = C.Errors(value).First() // const first = {\n // schema: { type: 'number' },\n // path: '/x',\n // value: undefined,\n // message: 'Expected number'\n // }\n\nconst all = [...C.Errors(value)] // const all = [{\\\n // schema: { type: 'number' },\\\n // path: '/x',\\\n // value: undefined,\\\n // message: 'Expected number'\\\n // }, {\\\n // schema: { type: 'number' },\\\n // path: '/y',\\\n // value: undefined,\\\n // message: 'Expected number'\\\n // }, {\\\n // schema: { type: 'number' },\\\n // path: '/z',\\\n // value: undefined,\\\n // message: 'Expected number'\\\n // }]\n```\n\nUse the Code function to generate assertion functions as strings. This function can be used to generate code that can be written to disk as importable modules. This technique is sometimes referred to as Ahead of Time (AOT) compilation. The following generates code to check a string.\n\n```\nconst C = TypeCompiler.Code(Type.String()) // const C = `return function check(value) {\n // return (\n // (typeof value === 'string')\n // )\n // }`\n```\n\n## TypeMap\n\n[Permalink: TypeMap](https://www.npmjs.com/package/@sinclair/typebox#typemap)\n\nTypeBox offers an external package for bidirectional mapping between TypeBox, Valibot, and Zod type libraries. It also includes syntax parsing support for Valibot and Zod and supports the Standard Schema specification. For more details on TypeMap, refer to the project repository.\n\n[TypeMap Repository](https://github.com/sinclairzx81/typemap)\n\n### Usage\n\n[Permalink: Usage](https://www.npmjs.com/package/@sinclair/typebox#usage-1)\n\nTypeMap needs to be installed separately\n\n```\n$ npm install @sinclair/typemap\n```\n\nOnce installed it offers advanced structural remapping between various runtime type libraries ( [Example](https://www.typescriptlang.org/play/?moduleResolution=99&module=199&ts=5.8.0-beta#code/JYWwDg9gTgLgBAbzgFQJ5gKYCEIA8A0cAyqgHYwCGBcAWhACZwC+cAZlBCHAOQACAzsFIBjADYVgUAPQx0GEBTDcAUMuERS-eMjgBeFHJy4AFAAMkuAFxxSAVxAAjDFEKprdx88IAvd-adQzKYAlHBwUlJw6pra1sgA8g4AVhjCMAA8CMphObl5+QWFRcW5ETlWKABy-s4A3NkljU3NBWVhblU1UPUtvX3FbXC+nZ7dDf0TE2VMAHyq0VrEesRklCbIoS1lC-BE1twWfqOuRwE+p87MKmoaiwBKy3T0xkTBAHRgFFD8GMZ2oqJNnltrd4HdrFlJltImEKh4Aj0oU1Bh14XVxkiBjChhcxpjGtMwkA))\n\n```\nimport { TypeBox, Syntax, Zod } from '@sinclair/typemap'\n\nconst T = TypeBox(`{ x: number, y: number, z: number }`) // const T: TObject<{\n // x: TNumber;\n // y: TNumber;\n // z: TNumber;\n // }>\n\nconst S = Syntax(T) // const S: '{ x: number, y: number, z: number }'\n\nconst R = Zod(S).parse(null) // const R: {\n // x: number;\n // y: number;\n // z: number;\n // }\n```\n\n## TypeSystem\n\n[Permalink: TypeSystem](https://www.npmjs.com/package/@sinclair/typebox#typesystem)\n\nThe TypeBox TypeSystem module provides configurations to use either Json Schema or TypeScript type checking semantics. Configurations made to the TypeSystem module are observed by the TypeCompiler, Value and Error modules.\n\n### Policies\n\n[Permalink: Policies](https://www.npmjs.com/package/@sinclair/typebox#policies)\n\nTypeBox validates using standard Json Schema assertion policies by default. The TypeSystemPolicy module can override some of these to have TypeBox assert values inline with TypeScript static checks. It also provides overrides for certain checking rules related to non-serializable values (such as void) which can be helpful in Json based protocols such as Json Rpc 2.0.\n\nThe following overrides are available.\n\n```\nimport { TypeSystemPolicy } from '@sinclair/typebox/system'\n\n// Disallow undefined values for optional properties (default is false)\n//\n// const A: { x?: number } = { x: undefined } - disallowed when enabled\n\nTypeSystemPolicy.ExactOptionalPropertyTypes = true\n\n// Allow arrays to validate as object types (default is false)\n//\n// const A: {} = [] - allowed in TS\n\nTypeSystemPolicy.AllowArrayObject = true\n\n// Allow numeric values to be NaN or + or - Infinity (default is false)\n//\n// const A: number = NaN - allowed in TS\n\nTypeSystemPolicy.AllowNaN = true\n\n// Allow void types to check with undefined and null (default is false)\n//\n// Used to signal void return on Json-Rpc 2.0 protocol\n\nTypeSystemPolicy.AllowNullVoid = true\n```\n\n## Error Function\n\n[Permalink: Error Function](https://www.npmjs.com/package/@sinclair/typebox#error-function)\n\nError messages in TypeBox can be customized by defining an ErrorFunction. This function allows for the localization of error messages as well as enabling custom error messages for custom types. By default, TypeBox will generate messages using the `en-US` locale. To support additional locales, you can replicate the function found in `src/errors/function.ts` and create a locale specific translation. The function can then be set via SetErrorFunction.\n\nThe following example shows an inline error function that intercepts errors for String, Number and Boolean only. The DefaultErrorFunction is used to return a default error message.\n\n```\nimport { SetErrorFunction, DefaultErrorFunction, ValueErrorType } from '@sinclair/typebox/errors'\n\nSetErrorFunction((error) => { // i18n override\n switch(error.errorType) {\n /* en-US */ case ValueErrorType.String: return 'Expected string'\n /* fr-FR */ case ValueErrorType.Number: return 'Nombre attendu'\n /* ko-KR */ case ValueErrorType.Boolean: return '예상 부울'\n /* en-US */ default: return DefaultErrorFunction(error)\n }\n})\nconst T = Type.Object({ // const T: TObject<{\n x: Type.String(), // TString,\n y: Type.Number(), // TNumber,\n z: Type.Boolean() // TBoolean\n}) // }>\n\nconst E = [...Value.Errors(T, { // const E = [{\\\n x: null, // type: 48,\\\n y: null, // schema: { ... },\\\n z: null // path: '/x',\\\n})] // value: null,\\\n // message: 'Expected string'\\\n // }, {\\\n // type: 34,\\\n // schema: { ... },\\\n // path: '/y',\\\n // value: null,\\\n // message: 'Nombre attendu'\\\n // }, {\\\n // type: 14,\\\n // schema: { ... },\\\n // path: '/z',\\\n // value: null,\\\n // message: '예상 부울'\\\n // }]\n```\n\n## TypeBox Workbench\n\n[Permalink: TypeBox Workbench](https://www.npmjs.com/package/@sinclair/typebox#typebox-workbench)\n\nTypeBox offers a web based code generation tool that can convert TypeScript types into TypeBox types as well as several other ecosystem libraries.\n\n[TypeBox Workbench Link Here](https://sinclairzx81.github.io/typebox-workbench/)\n\n## TypeBox Codegen\n\n[Permalink: TypeBox Codegen](https://www.npmjs.com/package/@sinclair/typebox#typebox-codegen)\n\nTypeBox provides a code generation library that can be integrated into toolchains to automate type translation between TypeScript and TypeBox. This library also includes functionality to transform TypeScript types to other ecosystem libraries.\n\n[TypeBox Codegen Link Here](https://github.com/sinclairzx81/typebox-codegen)\n\n## Ecosystem\n\n[Permalink: Ecosystem](https://www.npmjs.com/package/@sinclair/typebox#ecosystem)\n\nThe following is a list of community packages that offer general tooling, extended functionality and framework integration support for TypeBox.\n\n| Package | Description |\n| --- | --- |\n| [drizzle-typebox](https://www.npmjs.com/package/drizzle-typebox) | Generates TypeBox types from Drizzle ORM schemas |\n| [elysia](https://github.com/elysiajs/elysia) | Fast and friendly Bun web framework |\n| [fastify-type-provider-typebox](https://github.com/fastify/fastify-type-provider-typebox) | Fastify TypeBox integration with the Fastify Type Provider |\n| [feathersjs](https://github.com/feathersjs/feathers) | The API and real-time application framework |\n| [fetch-typebox](https://github.com/erfanium/fetch-typebox) | Drop-in replacement for fetch that brings easy integration with TypeBox |\n| [@lonli-lokli/fetcher-typebox](https://github.com/Lonli-Lokli/fetcher-ts/tree/master/packages/fetcher-typebox) | A strongly-typed fetch wrapper for TypeScript applications with optional runtime validation using TypeBox |\n| [h3-typebox](https://github.com/kevinmarrec/h3-typebox) | Schema validation utilities for h3 using TypeBox & Ajv |\n| [http-wizard](https://github.com/flodlc/http-wizard) | Type safe http client library for Fastify |\n| [json2typebox](https://github.com/hacxy/json2typebox) | Creating TypeBox code from Json Data |\n| [nominal-typebox](https://github.com/Coder-Spirit/nominal/tree/main/%40coderspirit/nominal-typebox) | Allows devs to integrate nominal types into TypeBox schemas |\n| [openapi-box](https://github.com/geut/openapi-box) | Generate TypeBox types from OpenApi IDL + Http client library |\n| [prismabox](https://github.com/m1212e/prismabox) | Converts a prisma.schema to TypeBox schema matching the database models |\n| [schema2typebox](https://github.com/xddq/schema2typebox) | Creating TypeBox code from Json Schemas |\n| [sveltekit-superforms](https://github.com/ciscoheat/sveltekit-superforms) | A comprehensive SvelteKit form library for server and client validation |\n| [ts2typebox](https://github.com/xddq/ts2typebox) | Creating TypeBox code from Typescript types |\n| [typebox-cli](https://github.com/gsuess/typebox-cli) | Generate Schema with TypeBox from the CLI |\n| [typebox-form-parser](https://github.com/jtlapp/typebox-form-parser) | Parses form and query data based on TypeBox schemas |\n| [typebox-schema-faker](https://github.com/iam-medvedev/typebox-schema-faker) | Generate fake data from TypeBox schemas for testing, prototyping and development |\n\n## Benchmark\n\n[Permalink: Benchmark](https://www.npmjs.com/package/@sinclair/typebox#benchmark)\n\nThis project maintains a set of benchmarks that measure Ajv, Value and TypeCompiler compilation and validation performance. These benchmarks can be run locally by cloning this repository and running `npm run benchmark`. The results below show for Ajv version 8.12.0 running on Node 20.10.0.\n\nFor additional comparative benchmarks, please refer to [typescript-runtime-type-benchmarks](https://moltar.github.io/typescript-runtime-type-benchmarks/).\n\n### Compile\n\n[Permalink: Compile](https://www.npmjs.com/package/@sinclair/typebox#compile)\n\nThis benchmark measures compilation performance for varying types.\n\n```\n┌────────────────────────────┬────────────┬──────────────┬──────────────┬──────────────┐\n│ (index) │ Iterations │ Ajv │ TypeCompiler │ Performance │\n├────────────────────────────┼────────────┼──────────────┼──────────────┼──────────────┤\n│ Literal_String │ 1000 │ ' 211 ms' │ ' 8 ms' │ ' 26.38 x' │\n│ Literal_Number │ 1000 │ ' 185 ms' │ ' 5 ms' │ ' 37.00 x' │\n│ Literal_Boolean │ 1000 │ ' 195 ms' │ ' 4 ms' │ ' 48.75 x' │\n│ Primitive_Number │ 1000 │ ' 149 ms' │ ' 7 ms' │ ' 21.29 x' │\n│ Primitive_String │ 1000 │ ' 135 ms' │ ' 5 ms' │ ' 27.00 x' │\n│ Primitive_String_Pattern │ 1000 │ ' 193 ms' │ ' 10 ms' │ ' 19.30 x' │\n│ Primitive_Boolean │ 1000 │ ' 152 ms' │ ' 4 ms' │ ' 38.00 x' │\n│ Primitive_Null │ 1000 │ ' 147 ms' │ ' 4 ms' │ ' 36.75 x' │\n│ Object_Unconstrained │ 1000 │ ' 1065 ms' │ ' 26 ms' │ ' 40.96 x' │\n│ Object_Constrained │ 1000 │ ' 1183 ms' │ ' 26 ms' │ ' 45.50 x' │\n│ Object_Vector3 │ 1000 │ ' 407 ms' │ ' 9 ms' │ ' 45.22 x' │\n│ Object_Box3D │ 1000 │ ' 1777 ms' │ ' 24 ms' │ ' 74.04 x' │\n│ Tuple_Primitive │ 1000 │ ' 485 ms' │ ' 11 ms' │ ' 44.09 x' │\n│ Tuple_Object │ 1000 │ ' 1344 ms' │ ' 17 ms' │ ' 79.06 x' │\n│ Composite_Intersect │ 1000 │ ' 606 ms' │ ' 14 ms' │ ' 43.29 x' │\n│ Composite_Union │ 1000 │ ' 522 ms' │ ' 17 ms' │ ' 30.71 x' │\n│ Math_Vector4 │ 1000 │ ' 851 ms' │ ' 9 ms' │ ' 94.56 x' │\n│ Math_Matrix4 │ 1000 │ ' 406 ms' │ ' 10 ms' │ ' 40.60 x' │\n│ Array_Primitive_Number │ 1000 │ ' 367 ms' │ ' 6 ms' │ ' 61.17 x' │\n│ Array_Primitive_String │ 1000 │ ' 339 ms' │ ' 7 ms' │ ' 48.43 x' │\n│ Array_Primitive_Boolean │ 1000 │ ' 325 ms' │ ' 5 ms' │ ' 65.00 x' │\n│ Array_Object_Unconstrained │ 1000 │ ' 1863 ms' │ ' 21 ms' │ ' 88.71 x' │\n│ Array_Object_Constrained │ 1000 │ ' 1535 ms' │ ' 18 ms' │ ' 85.28 x' │\n│ Array_Tuple_Primitive │ 1000 │ ' 829 ms' │ ' 14 ms' │ ' 59.21 x' │\n│ Array_Tuple_Object │ 1000 │ ' 1674 ms' │ ' 14 ms' │ ' 119.57 x' │\n│ Array_Composite_Intersect │ 1000 │ ' 789 ms' │ ' 13 ms' │ ' 60.69 x' │\n│ Array_Composite_Union │ 1000 │ ' 822 ms' │ ' 15 ms' │ ' 54.80 x' │\n│ Array_Math_Vector4 │ 1000 │ ' 1129 ms' │ ' 14 ms' │ ' 80.64 x' │\n│ Array_Math_Matrix4 │ 1000 │ ' 673 ms' │ ' 9 ms' │ ' 74.78 x' │\n└────────────────────────────┴────────────┴──────────────┴──────────────┴──────────────┘\n```\n\n### Validate\n\n[Permalink: Validate](https://www.npmjs.com/package/@sinclair/typebox#validate)\n\nThis benchmark measures validation performance for varying types.\n\n```\n┌────────────────────────────┬────────────┬──────────────┬──────────────┬──────────────┬──────────────┐\n│ (index) │ Iterations │ ValueCheck │ Ajv │ TypeCompiler │ Performance │\n├────────────────────────────┼────────────┼──────────────┼──────────────┼──────────────┼──────────────┤\n│ Literal_String │ 1000000 │ ' 17 ms' │ ' 5 ms' │ ' 5 ms' │ ' 1.00 x' │\n│ Literal_Number │ 1000000 │ ' 14 ms' │ ' 18 ms' │ ' 9 ms' │ ' 2.00 x' │\n│ Literal_Boolean │ 1000000 │ ' 14 ms' │ ' 20 ms' │ ' 9 ms' │ ' 2.22 x' │\n│ Primitive_Number │ 1000000 │ ' 17 ms' │ ' 19 ms' │ ' 9 ms' │ ' 2.11 x' │\n│ Primitive_String │ 1000000 │ ' 17 ms' │ ' 18 ms' │ ' 10 ms' │ ' 1.80 x' │\n│ Primitive_String_Pattern │ 1000000 │ ' 172 ms' │ ' 46 ms' │ ' 41 ms' │ ' 1.12 x' │\n│ Primitive_Boolean │ 1000000 │ ' 14 ms' │ ' 19 ms' │ ' 10 ms' │ ' 1.90 x' │\n│ Primitive_Null │ 1000000 │ ' 16 ms' │ ' 19 ms' │ ' 9 ms' │ ' 2.11 x' │\n│ Object_Unconstrained │ 1000000 │ ' 437 ms' │ ' 28 ms' │ ' 14 ms' │ ' 2.00 x' │\n│ Object_Constrained │ 1000000 │ ' 653 ms' │ ' 46 ms' │ ' 37 ms' │ ' 1.24 x' │\n│ Object_Vector3 │ 1000000 │ ' 201 ms' │ ' 22 ms' │ ' 12 ms' │ ' 1.83 x' │\n│ Object_Box3D │ 1000000 │ ' 961 ms' │ ' 37 ms' │ ' 19 ms' │ ' 1.95 x' │\n│ Object_Recursive │ 1000000 │ ' 3715 ms' │ ' 363 ms' │ ' 174 ms' │ ' 2.09 x' │\n│ Tuple_Primitive │ 1000000 │ ' 107 ms' │ ' 23 ms' │ ' 11 ms' │ ' 2.09 x' │\n│ Tuple_Object │ 1000000 │ ' 375 ms' │ ' 28 ms' │ ' 15 ms' │ ' 1.87 x' │\n│ Composite_Intersect │ 1000000 │ ' 377 ms' │ ' 22 ms' │ ' 12 ms' │ ' 1.83 x' │\n│ Composite_Union │ 1000000 │ ' 337 ms' │ ' 30 ms' │ ' 17 ms' │ ' 1.76 x' │\n│ Math_Vector4 │ 1000000 │ ' 137 ms' │ ' 23 ms' │ ' 11 ms' │ ' 2.09 x' │\n│ Math_Matrix4 │ 1000000 │ ' 576 ms' │ ' 37 ms' │ ' 28 ms' │ ' 1.32 x' │\n│ Array_Primitive_Number │ 1000000 │ ' 145 ms' │ ' 23 ms' │ ' 12 ms' │ ' 1.92 x' │\n│ Array_Primitive_String │ 1000000 │ ' 152 ms' │ ' 22 ms' │ ' 13 ms' │ ' 1.69 x' │\n│ Array_Primitive_Boolean │ 1000000 │ ' 131 ms' │ ' 20 ms' │ ' 13 ms' │ ' 1.54 x' │\n│ Array_Object_Unconstrained │ 1000000 │ ' 2821 ms' │ ' 62 ms' │ ' 45 ms' │ ' 1.38 x' │\n│ Array_Object_Constrained │ 1000000 │ ' 2958 ms' │ ' 119 ms' │ ' 134 ms' │ ' 0.89 x' │\n│ Array_Object_Recursive │ 1000000 │ ' 14695 ms' │ ' 1621 ms' │ ' 635 ms' │ ' 2.55 x' │\n│ Array_Tuple_Primitive │ 1000000 │ ' 478 ms' │ ' 35 ms' │ ' 28 ms' │ ' 1.25 x' │\n│ Array_Tuple_Object │ 1000000 │ ' 1623 ms' │ ' 63 ms' │ ' 48 ms' │ ' 1.31 x' │\n│ Array_Composite_Intersect │ 1000000 │ ' 1582 ms' │ ' 43 ms' │ ' 30 ms' │ ' 1.43 x' │\n│ Array_Composite_Union │ 1000000 │ ' 1331 ms' │ ' 76 ms' │ ' 40 ms' │ ' 1.90 x' │\n│ Array_Math_Vector4 │ 1000000 │ ' 564 ms' │ ' 38 ms' │ ' 24 ms' │ ' 1.58 x' │\n│ Array_Math_Matrix4 │ 1000000 │ ' 2382 ms' │ ' 111 ms' │ ' 83 ms' │ ' 1.34 x' │\n└────────────────────────────┴────────────┴──────────────┴──────────────┴──────────────┴──────────────┘\n```\n\n### Compression\n\n[Permalink: Compression](https://www.npmjs.com/package/@sinclair/typebox#compression)\n\nThe following table lists esbuild compiled and minified sizes for each TypeBox module.\n\n```\n┌──────────────────────┬────────────┬────────────┬─────────────┐\n│ (index) │ Compiled │ Minified │ Compression │\n├──────────────────────┼────────────┼────────────┼─────────────┤\n│ typebox/compiler │ '122.4 kb' │ ' 53.4 kb' │ '2.29 x' │\n│ typebox/errors │ ' 67.6 kb' │ ' 29.6 kb' │ '2.28 x' │\n│ typebox/syntax │ '132.9 kb' │ ' 54.2 kb' │ '2.45 x' │\n│ typebox/system │ ' 7.4 kb' │ ' 3.2 kb' │ '2.33 x' │\n│ typebox/value │ '150.1 kb' │ ' 62.2 kb' │ '2.41 x' │\n│ typebox │ '106.8 kb' │ ' 43.2 kb' │ '2.47 x' │\n└──────────────────────┴────────────┴────────────┴─────────────┘\n```\n\n## Contribute\n\n[Permalink: Contribute](https://www.npmjs.com/package/@sinclair/typebox#contribute)\n\nTypeBox is open to community contribution. Please ensure you submit an open issue before submitting your pull request. The TypeBox project prefers open community discussion before accepting new features.\n\n## Readme\n\n### Keywords\n\n- [typescript](https://www.npmjs.com/search?q=keywords:typescript)\n- [json-schema](https://www.npmjs.com/search?q=keywords:json-schema)\n- [validate](https://www.npmjs.com/search?q=keywords:validate)\n- [typecheck](https://www.npmjs.com/search?q=keywords:typecheck)\n\nViewing @sinclair/typebox version 0.34.49","metadata":{"og:description":"Json Schema Type Builder with Static Type Resolution for TypeScript. Latest version: 0.34.49, last published: a day ago. Start using @sinclair/typebox in your project by running `npm i @sinclair/typebox`. There are 6088 other projects in the npm registry using @sinclair/typebox.","ogDescription":"Json Schema Type Builder with Static Type Resolution for TypeScript. Latest version: 0.34.49, last published: a day ago. Start using @sinclair/typebox in your project by running `npm i @sinclair/typebox`. There are 6088 other projects in the npm registry using @sinclair/typebox.","og:url":"https://www.npmjs.com/package/@sinclair/typebox","msapplication-config":"https://static-production.npmjs.com/668aac888e52ae13cac9cfd71fabd31f.xml","mobile-web-app-capable":"yes","twitter:description":"Json Schema Type Builder with Static Type Resolution for TypeScript. Latest version: 0.34.49, last published: a day ago. Start using @sinclair/typebox in your project by running `npm i @sinclair/typebox`. There are 6088 other projects in the npm registry using @sinclair/typebox.","ogImage":"https://static-production.npmjs.com/338e4905a2684ca96e08c7780fc68412.png","msapplication-TileColor":"#cb3837","description":"Json Schema Type Builder with Static Type Resolution for TypeScript. Latest version: 0.34.49, last published: a day ago. Start using @sinclair/typebox in your project by running `npm i @sinclair/typebox`. There are 6088 other projects in the npm registry using @sinclair/typebox.","og:title":"@sinclair/typebox","keywords":"typescript,json-schema,validate,typecheck","theme-color":"#cb3837","ogUrl":"https://www.npmjs.com/package/@sinclair/typebox","twitter:card":"summary","apple-mobile-web-app-capable":"yes","twitter:url":"https://www.npmjs.com/package/@sinclair/typebox","twitter:title":"npm: @sinclair/typebox","ogTitle":"@sinclair/typebox","title":"@sinclair/typebox - npm","og:site_name":"npm","og:image":"https://static-production.npmjs.com/338e4905a2684ca96e08c7780fc68412.png","msapplication-TileImage":"https://static-production.npmjs.com/7a7ffabbd910fc60161bc04f2cee4160.png","viewport":"width=device-width,minimum-scale=1.0,initial-scale=1,user-scalable=yes","language":"en","ogSiteName":"npm","favicon":"https://static-production.npmjs.com/b0f1a8318363185cc2ea6a40ac23eeb2.png","scrapeId":"019d3953-4883-75d8-89ea-c2e221192550","sourceURL":"https://www.npmjs.com/package/@sinclair/typebox","url":"https://www.npmjs.com/package/@sinclair/typebox","statusCode":200,"contentType":"text/html","timezone":"America/New_York","proxyUsed":"basic","cacheState":"miss","indexId":"9f6e6fed-410c-44dc-9f32-889aa340e926","creditsUsed":1}},{"url":"https://github.com/sinclairzx81/typebox/discussions/1189","title":"Using Typebox validator on non-Typebox JSON schema #1189","description":"On some part of my app, I have some JSON schemas coming from configuration code, so it cannot be turned into Typebox constructs.","position":5,"category":"github","markdown":"[Skip to content](https://github.com/sinclairzx81/typebox/discussions/1189#start-of-content)\n\nYou signed in with another tab or window. [Reload](https://github.com/sinclairzx81/typebox/discussions/1189) to refresh your session.You signed out in another tab or window. [Reload](https://github.com/sinclairzx81/typebox/discussions/1189) to refresh your session.You switched accounts on another tab or window. [Reload](https://github.com/sinclairzx81/typebox/discussions/1189) to refresh your session.Dismiss alert\n\n{{ message }}\n\n[sinclairzx81](https://github.com/sinclairzx81)/ **[typebox](https://github.com/sinclairzx81/typebox)** Public\n\n- [Notifications](https://github.com/login?return_to=%2Fsinclairzx81%2Ftypebox) You must be signed in to change notification settings\n- [Fork\\\\\n197](https://github.com/login?return_to=%2Fsinclairzx81%2Ftypebox)\n- [Star\\\\\n6.6k](https://github.com/login?return_to=%2Fsinclairzx81%2Ftypebox)\n\n\n# Using Typebox validator on non-Typebox JSON schema \\#1189\n\n[Answered](https://github.com/sinclairzx81/typebox/discussions/1189#discussioncomment-12320932) by [sinclairzx81](https://github.com/sinclairzx81 \"sinclairzx81\")\n\n[yacinehmito](https://github.com/yacinehmito)\n\nasked this question in\n[Q&A](https://github.com/sinclairzx81/typebox/discussions/categories/q-a)\n\n[Using Typebox validator on non-Typebox JSON schema](https://github.com/sinclairzx81/typebox/discussions/1189#top)#1189\n\n[\\\\\nyacinehmito](https://github.com/yacinehmito)\n\non Feb 25, 2025Feb 26, 2025·\n1 comments\n·\n1 reply\n\n\n[Answered](https://github.com/sinclairzx81/typebox/discussions/1189#discussioncomment-12320932)by [sinclairzx81](https://github.com/sinclairzx81 \"sinclairzx81\")[Return to top](https://github.com/sinclairzx81/typebox/discussions/1189#top)\n\nDiscussion options\n\n### Uh oh!\n\nThere was an error while loading. [Please reload this page](https://github.com/sinclairzx81/typebox/discussions/1189).\n\n# {{title}}\n\nQuote reply\n\n## [\\ yacinehmito](https://github.com/yacinehmito) [on Feb 25, 2025Feb 26, 2025](https://github.com/sinclairzx81/typebox/discussions/1189\\#discussion-8013762)\n\n -\n\n\n| |\n| --- |\n| On some part of my app, I have some JSON schemas coming from configuration code, so it cannot be turned into Typebox constructs. I still want to validate data against those schemas (knowing I will not get type inference).<br>From what I understand, `Parse` is only compatible with objects built with Typebox, so I'd have to include another validator to the project just for these types.<br>Is my assumption correct? If so, which constraint makes validation only available to schemas built with Typebox? |\n\nBetaWas this translation helpful? [Give feedback.](https://github.com/sinclairzx81/typebox/discussions/1189#)\n\n1You must be logged in to vote\n\nAll reactions\n\nAnswered by\n[sinclairzx81](https://github.com/sinclairzx81)[on Feb 26, 2025Feb 26, 2025](https://github.com/sinclairzx81/typebox/discussions/1189#discussioncomment-12320932)\n\nHi,\n\n* * *\n\n> On some part of my app, I have some JSON schemas coming from configuration code, so it cannot be turned into Typebox constructs. I still want to validate data against those schemas (knowing I will not get type inference).\n\nIt is actually possible to convert raw schematics into TypeBox types. Have a look at the following URL + Example\n\n[https://github.com/sinclairzx81/typebox/blob/master/example/prototypes/from-schema.ts](https://github.com/sinclairzx81/typebox/blob/master/example/prototypes/from-schema.ts)\n\n```\nimport { FromSchema } from './prototypes/from-schema'\n\nconst T = FromSchema({\n type: 'object',\n required: ['x', 'y', 'z'],\n properties: {\n x: { type: 'number' },\n y: { type: 'number' },\n z: { type: 'number' },\n }\n} as const) // or 'as unknown' if the sche…\n```\n\n[View full answer](https://github.com/sinclairzx81/typebox/discussions/1189#discussioncomment-12320932)\n\n## Replies: 1 comment · 1 reply\n\nComment options\n\n### Uh oh!\n\nThere was an error while loading. [Please reload this page](https://github.com/sinclairzx81/typebox/discussions/1189).\n\n# {{title}}\n\nQuote reply\n\nedited\n\n### Uh oh!\n\nThere was an error while loading. [Please reload this page](https://github.com/sinclairzx81/typebox/discussions/1189).\n\n# {{editor}}'s edit\n\n{{actor}} deleted this content\n.\n\n# {{editor}}'s edit\n\n### [\\ sinclairzx81](https://github.com/sinclairzx81) [on Feb 26, 2025Feb 26, 2025](https://github.com/sinclairzx81/typebox/discussions/1189\\#discussioncomment-12320932) Maintainer\n\n -\n\n\n| |\n| --- |\n| Hi,<br>* * *<br>> On some part of my app, I have some JSON schemas coming from configuration code, so it cannot be turned into Typebox constructs. I still want to validate data against those schemas (knowing I will not get type inference).<br>It is actually possible to convert raw schematics into TypeBox types. Have a look at the following URL + Example<br>[https://github.com/sinclairzx81/typebox/blob/master/example/prototypes/from-schema.ts](https://github.com/sinclairzx81/typebox/blob/master/example/prototypes/from-schema.ts)<br>```<br>import { FromSchema } from './prototypes/from-schema'<br>const T = FromSchema({ <br> type: 'object',<br> required: ['x', 'y', 'z'],<br> properties: {<br> x: { type: 'number' },<br> y: { type: 'number' },<br> z: { type: 'number' },<br> }<br>} as const) // or 'as unknown' if the schematics originate from elsewhere<br>console.log(T)<br>```<br>The FromSchema type is currently treated as an extension / prototype for now.<br>* * *<br>> ... which constraint makes validation only available to schemas built with Typebox?<br>The primary constraint is that TypeBox requires specific symbols to be applied appropriately to schematics. TypeBox validators operate almost exclusively by introspecting Kind, Hint, Modifier, and Transform descriptor symbols applied to schematics. As a result, remote schematics require a loading phase to apply these symbols correctly (as shown in the FromSchema example above).<br>There's a couple of reasons for this design ....<br>1. Ambiguity resolution: Symbol descriptors help differentiate between ambiguous schematics. For example, the schema `{}` could represent either `any` or `unknown`. In addition, symbols serve as a contract for a schematic, ensuring that an Object symbol means the schematic conforms to the object [representation](https://github.com/sinclairzx81/typebox?tab=readme-ov-file#types-json) mandated by TypeBox. This mostly prevents ambiguity if users were to attempt to mix different schema vocabularies.<br>2. Performance optimizations: Symbols [accelerate schema introspection and compilation](https://github.com/sinclairzx81/typebox?tab=readme-ov-file#compile). Instead of introspecting each property of a schema individually to learn what the schema is representing, TypeBox can inspect a single symbol descriptor to determine the schema's exact structure. This helps to speed up application start times when running TypeBox JIT on certain cloud infrastructure.<br>3. Support for multiple schema representations: Symbols enable TypeBox to potentially support different schema representations under a common named descriptor. For example, Tuple structures are represented differently in Draft 7 and Draft 2020-12 but most users probably don't care about the representation, only that a type is Tuple. Having a named descriptor for tuple-like schematics captures structural intent, but permits flexibility in representation (including for entirely different specifications, such as Json Type Definition)<br>In short, the reason schematics can't be loaded directly is because they need to be normalized to the subset of schematics supported by TypeBox then have symbols applied accordingly.<br>* * *<br>Hope this brings some insight. From your query, If you need to load remote schematics, consider the FromSchema function. Alternatively, Ajv is still a really good option for validation.<br>I will say though. The symbol requirement for schematics was devised several years ago to work through some fairly difficult alignment issues between TypeScript and Json Schema, but I've not been entirely happy with the design (mostly because it makes loading remote schematics more difficult than it needs to be). I will be reviewing the implementation at some point, and I think there may be some alternative approaches to schema differentiation that could make removing symbols more feasible. Something for down the road tho.<br>Happy to discuss more if you have any questions<br>Cheers<br>S |\n\nBetaWas this translation helpful? [Give feedback.](https://github.com/sinclairzx81/typebox/discussions/1189#)\n\nMarked as answer\n\n2You must be logged in to vote\n\nAll reactions\n\n1 reply\n\n\n[](https://github.com/yacinehmito)\n\nComment options\n\n### Uh oh!\n\nThere was an error while loading. [Please reload this page](https://github.com/sinclairzx81/typebox/discussions/1189).\n\n# {{title}}\n\nQuote reply\n\n#### [yacinehmito](https://github.com/yacinehmito) [on Mar 1, 2025Mar 2, 2025](https://github.com/sinclairzx81/typebox/discussions/1189\\#discussioncomment-12363007) Author\n\n -\n\n\n| |\n| --- |\n| Thank you very much for this thorough answer! |\n\nBetaWas this translation helpful? [Give feedback.](https://github.com/sinclairzx81/typebox/discussions/1189#)\n\nAll reactions\n\nAnswer selected by [sinclairzx81](https://github.com/sinclairzx81)\n\n[Sign up for free](https://github.com/join?source=comment-repo) **to join this conversation on GitHub**.\nAlready have an account?\n[Sign in to comment](https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fsinclairzx81%2Ftypebox%2Fdiscussions%2F1189)\n\nCategory\n\n\n[\\\\\n\\\\\nQ&A](https://github.com/sinclairzx81/typebox/discussions/categories/q-a)\n\nLabels\n\n\nNone yet\n\n\n2 participants\n\n\n[](https://github.com/yacinehmito)[](https://github.com/sinclairzx81)\n\nHeading\n\nBold\n\nItalic\n\nQuote\n\nCode\n\nLink\n\n* * *\n\nNumbered list\n\nUnordered list\n\nTask list\n\n* * *\n\nAttach files\n\nMention\n\nReference\n\n# Select a reply\n\nLoading\n\n[Create a new saved reply](https://github.com/sinclairzx81/typebox/discussions/1189)\n\n👍1 reacted with thumbs up emoji👎1 reacted with thumbs down emoji😄1 reacted with laugh emoji🎉1 reacted with hooray emoji😕1 reacted with confused emoji❤️1 reacted with heart emoji🚀1 reacted with rocket emoji👀1 reacted with eyes emoji\n\nYou can’t perform that action at this time.","metadata":{"html-safe-nonce":"234f1d4c83ee50df038cb6c2ca62e8651c6e7d3ca0244a982443e91d968700d4","current-catalog-service-hash":"9f0abe34da433c9b6db74bffa2466494a717b579a96b30a5d252e5090baea7be","apple-itunes-app":"app-id=1477376905, app-argument=https://github.com/_view_fragments/Voltron::DiscussionsFragmentsController/show/sinclairzx81/typebox/1189/discussion_layout","og:url":"https://github.com/sinclairzx81/typebox/discussions/1189","hovercard-subject-tag":"discussion:8013762","ogTitle":"Using Typebox validator on non-Typebox JSON schema · sinclairzx81/typebox · Discussion #1189","twitter:description":"On some part of my app, I have some JSON schemas coming from configuration code, so it cannot be turned into Typebox constructs. I still want to validate data against those schemas (knowing I will ...","description":"Using Typebox validator on non-Typebox JSON schema","analytics-location":"/<user-name>/<repo-name>/voltron/discussions_fragments/discussion_layout","og:image:width":"1200","browser-stats-url":"https://api.github.com/_private/browser/stats","og:image:height":"600","visitor-hmac":"826a4448396c241fcc2507ce8ad334f3aee5ee2ac0d6ab41813c2f116c4aa84a","expected-hostname":"github.com","disable-turbo":"false","octolytics-dimension-repository_public":"true","title":"Using Typebox validator on non-Typebox JSON schema · sinclairzx81/typebox · Discussion #1189 · GitHub","octolytics-url":"https://collector.github.com/github/collect","language":"en","route-controller":"voltron_discussions_fragments","og:type":"object","og:description":"On some part of my app, I have some JSON schemas coming from configuration code, so it cannot be turned into Typebox constructs. I still want to validate data against those schemas (knowing I will ...","octolytics-dimension-repository_network_root_id":"87454905","github-keyboard-shortcuts":"repository,copilot","og:site_name":"GitHub","og:image:alt":"On some part of my app, I have some JSON schemas coming from configuration code, so it cannot be turned into Typebox constructs. I still want to validate data against those schemas (knowing I will ...","octolytics-dimension-user_id":"3048342","twitter:site":"@github","color-scheme":"light dark","hostname":"github.com","fetch-nonce":"v2:03c939a2-439a-f738-789a-ebbd9968f9a7","go-import":"github.com/sinclairzx81/typebox git https://github.com/sinclairzx81/typebox.git","ogUrl":"https://github.com/sinclairzx81/typebox/discussions/1189","release":"51d2e33e3d1e4839c3ced5f8e35c7a47d3a60f32","octolytics-dimension-repository_is_fork":"false","ogDescription":"On some part of my app, I have some JSON schemas coming from configuration code, so it cannot be turned into Typebox constructs. I still want to validate data against those schemas (knowing I will ...","fb:app_id":"1401488693436528","google-site-verification":"Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I","twitter:card":"summary_large_image","octolytics-dimension-repository_network_root_nwo":"sinclairzx81/typebox","browser-errors-url":"https://api.github.com/_private/browser/errors","turbo-cache-control":"no-preview","user-login":"","twitter:title":"Using Typebox validator on non-Typebox JSON schema · sinclairzx81/typebox · Discussion #1189","octolytics-dimension-repository_id":"87454905","og:image":"https://opengraph.githubassets.com/833223f058cbefe61d71a1c90f85ffc822b9eab50031138c56a4dfe28ead6f5b/sinclairzx81/typebox/discussions/1189","og:title":"Using Typebox validator on non-Typebox JSON schema · sinclairzx81/typebox · Discussion #1189","ogImage":"https://opengraph.githubassets.com/833223f058cbefe61d71a1c90f85ffc822b9eab50031138c56a4dfe28ead6f5b/sinclairzx81/typebox/discussions/1189","theme-color":"#1e2327","ogSiteName":"GitHub","route-pattern":"/_view_fragments/Voltron::DiscussionsFragmentsController/show/:user_id/:repository/:discussion_number/discussion_layout(.:format)","route-action":"discussion_layout","viewport":"width=device-width","visitor-payload":"eyJyZWZlcnJlciI6Imh0dHBzOi8vd3d3Lmdvb2dsZS5jb20vIiwicmVxdWVzdF9pZCI6IjZFQUY6MkNGNUNBOjQ3QkU0Qjo1QzEyQTE6NjlDOTBCMTQiLCJ2aXNpdG9yX2lkIjoiMzc0ODczODE1ODg0Mjk0MDE4MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9","octolytics-dimension-repository_nwo":"sinclairzx81/typebox","ui-target":"full","turbo-body-classes":"logged-out env-production page-responsive","twitter:image":"https://opengraph.githubassets.com/833223f058cbefe61d71a1c90f85ffc822b9eab50031138c56a4dfe28ead6f5b/sinclairzx81/typebox/discussions/1189","request-id":"6EAF:2CF5CA:47BE4B:5C12A1:69C90B14","octolytics-dimension-user_login":"sinclairzx81","favicon":"https://github.githubassets.com/favicons/favicon.svg","scrapeId":"019d3953-4883-75d8-89ea-c6b7fe11841d","sourceURL":"https://github.com/sinclairzx81/typebox/discussions/1189","url":"https://github.com/sinclairzx81/typebox/discussions/1189","statusCode":200,"contentType":"text/html; charset=utf-8","timezone":"America/New_York","proxyUsed":"basic","cacheState":"miss","indexId":"7c9366b0-ca03-4b9d-8c89-026ff0cd7592","creditsUsed":1}}]}} |