sinclairzx81/typebox là dự án TypeScript với 7.0k sao trong nhóm Frontend. JSON Schema Type Builder with Static Type Resolution for TypeScript
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
JSON Schema Type Builder with Static Type Resolution for TypeScript
Install
$ npm install typebox
Usage
import Type from 'typebox'
const T = Type.Object({ // const T = {
x: Type.Number(), // type: 'object',
y: Type.Number(), // required: ['x', 'y', 'z']
z: Type.Number() // properties: {
}) // x: { type: 'number' },
// y: { type: 'number' },
// z: { type: 'number' }
// },
// }
type T = Type.Static<typeof T> // type T = {
// x: number,
// y: number,
// z: number
// }
Overview
Documentation
TypeBox 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 that can be statically checked by TypeScript and runtime checked using standard JSON Schema validation.
This library is designed to allow JSON Schema to compose similar to how types compose within TypeScript's type system. It can be used as a simple tool to build up complex schematics or integrated into REST and RPC services to help validate data received over the wire.
License: MIT
Contents
Type
Script
Schema
Versions
Contribute
Type
Documentation | Example
TypeBox types are JSON Schema fragments that compose into more complex types. The library provides a core set of types for constructing JSON Schema compliant schematics, alongside extended types designed to model constructs native to JavaScript and TypeScript. The JSON Schema schematics produced by TypeBox can be passed directly to any compliant validator.
Example
The following creates a User type and infers with Static.
TypeBox includes a micro TypeScript engine that can transform TypeScript definitions to JSON Schema. The engine is fully type-safe and supports many programmable constructs including Conditional, Mapped, Indexed, Generics, Distributive Generics, and more.
Example
Syntax highlighting is available via the Visual Studio Marketplace.
import Type from 'typebox'
const Math = Type.Script(`
type Vector4 = { x: number, y: number, z: number, w: number }
type Vector3 = { x: number, y: number, z: number }
type Vector2 = { x: number, y: number }
`)
const Graphics = Type.Script(Math, `
type Vertex = {
position: Vector4,
normal: Vector3,
uv: Vector2
}
type Geometry = {
vertices: Vertex[],
indices: number[]
}
type Material = {
ambient: Vector4,
diffuse: Vector4,
specular: Vector4
}
type Mesh = {
geometry: Geometry,
material: Material
}
`)
type Mesh = Type.Static<typeof Graphics['Mesh']> // type Mesh = {
// geometry: { ... },
// material: { ... }
// }
Schema
Documentation | Example 1 | Example 2 | Example 3
TypeBox includes a high-performance JSON Schema JIT compiler that supports Draft 3 through to 2020-12. The compiler is designed to be a lightweight industry-grade alternative to Ajv and offers improved compilation and validation performance. It also offers automatic fallback to dynamic validation in JIT restricted environments such as Cloudflare Workers.
The compiler is available via optional sub module import.
import Schema from 'typebox/schema'
Compile
The compiler accepts TypeBox types as well as plain JSON Schema objects, and returns a Validator instance which can be used to check values. The following compiles a Vector type.
import Schema from 'typebox/schema'
// Compile
const Vector = Schema.Compile(Type.Script(`{
x: number
y: number
z: number
}`))
// Check
const valid = Vector.Check({ x: 1, y: 0, z: 0 }) // const valid: boolean
// Parse
const result = Vector.Parse({ x: 1, y: 0, z: 0 }) // const result: {
// x: number
// y: number
// z: number
// }
Compatibility
JSON Schema Test Suite | JSON Schema Compliance Suite
TypeBox supports all versions of JSON Schema and is heavily tested against the official JSON Schema Test Suite. It has high compatibility with modern specifications while also offering broad support for legacy versions if their semantics are not in conflict with modern specifications.
Spec
3
4
6
7
2019-09
2020-12
v1
additionalProperties
✅
✅
✅
✅
✅
✅
✅
allOf
-
✅
✅
✅
✅
✅
✅
anchor
-
-
-
-
✅
✅
✅
anchor-legacy
7/14
7/14
✅
✅
-
-
-
anyOf
-
✅
✅
✅
✅
✅
✅
boolean_schema
-
-
✅
✅
✅
✅
✅
const
-
-
✅
✅
✅
✅
✅
contains
-
-
✅
✅
✅
✅
✅
content
-
-
-
-
✅
✅
✅
default
✅
✅
✅
✅
✅
✅
✅
dependentRequired
23/24
✅
✅
✅
✅
✅
✅
dependentSchemas
✅
✅
✅
✅
✅
✅
✅
disallow
4/9
-
-
-
-
-
-
dynamicRef
-
-
-
-
-
✅
✅
enum
47/49
✅
✅
✅
✅
✅
✅
extends
4/10
-
-
-
-
-
-
format-color
9/12
-
-
-
-
-
-
format-date
✅
-
-
✅
✅
✅
✅
format-date-time
✅
✅
✅
✅
✅
✅
✅
format-duration
-
-
-
-
✅
✅
✅
format-email
✅
✅
✅
✅
✅
✅
✅
format-host-name
14/28
-
-
-
-
-
-
format-hostname
-
28/29
28/29
✅
✅
✅
28/29
format-idn-email
-
-
-
✅
✅
✅
✅
format-idn-hostname
-
-
-
✅
✅
✅
✅
format-ip-address
11/41
-
-
-
-
-
-
format-ipv4
-
✅
✅
✅
✅
✅
✅
format-ipv6
✅
✅
✅
✅
✅
✅
✅
format-iri
-
-
-
✅
✅
✅
✅
format-iri-reference
-
-
-
✅
✅
✅
✅
format-json-pointer
-
-
✅
✅
✅
✅
✅
format-regex
✅
-
-
✅
✅
✅
✅
format-relative-json-pointer
-
-
-
✅
✅
✅
✅
format-time
8/9
-
-
✅
✅
✅
42/45
format-unknown
✅
✅
✅
✅
✅
✅
-
format-uri
✅
✅
✅
✅
✅
✅
✅
format-uri-reference
-
-
✅
✅
✅
✅
✅
format-uri-template
-
-
✅
✅
✅
✅
✅
format-uuid
-
-
-
-
✅
✅
✅
id
-
-
✅
✅
✅
✅
✅
id-legacy
29/40
33/46
✅
✅
-
-
-
if-then-else
-
-
-
✅
✅
✅
✅
infinite-loop-detection
-
-
-
-
✅
✅
✅
infinite-loop-detection-legacy
✅
✅
✅
✅
-
-
-
items
✅
✅
✅
✅
✅
✅
✅
maximum
13/14
13/14
✅
✅
✅
✅
✅
maxItems
✅
✅
✅
✅
✅
✅
✅
maxLength
✅
✅
✅
✅
✅
✅
✅
maxProperties
-
✅
✅
✅
✅
✅
✅
minimum
16/17
16/17
✅
✅
✅
✅
✅
minItems
✅
✅
✅
✅
✅
✅
✅
minLength
✅
✅
✅
✅
✅
✅
✅
minProperties
-
✅
✅
✅
✅
✅
✅
multipleOf
8/13
✅
✅
✅
✅
✅
✅
not
-
✅
✅
✅
✅
✅
✅
oneOf
-
✅
✅
✅
✅
✅
✅
pattern
✅
✅
✅
✅
✅
✅
✅
patternProperties
✅
✅
✅
✅
✅
✅
✅
properties
✅
✅
✅
✅
✅
✅
✅
propertyNames
-
-
✅
✅
✅
✅
✅
recursiveRef
-
-
-
-
✅
-
-
ref
✅
✅
✅
✅
✅
✅
✅
ref-legacy
25/26
30/31
32/33
32/33
✅
-
-
required
3/4
✅
✅
✅
✅
✅
✅
type
92/99
✅
✅
✅
✅
✅
✅
unevaluatedItems
-
-
-
-
✅
✅
✅
unevaluatedProperties
-
-
-
-
✅
✅
✅
uniqueItems
✅
✅
✅
✅
✅
✅
✅
vocabulary
-
-
-
-
4/5
4/5
-
Performance
TypeBox tracks performance against AJV8 only as the defacto performance standard. For broader comparative benchmarks, refer to the following community maintained projects.
Runtime Benchmarks | Schema Benchmarks
Compile
The following table shows compile performance for various JSON Schema structures. These benchmarks measure the time required to build and runtime JIT schematics. Faster compilation results in faster application startup.
The following table shows validation performance for various JSON Schema structures. These benchmarks measure overall validation throughput for compiled schematics.
TypeBox ships two distinct versions that span two generations of the TypeScript compiler.
TypeBox
TypeScript
Description
1.x
6.0 - 7.0+
Latest. Developed against the TypeScript 7 native compiler. Provides advanced type inference and native JSON Schema 2020-12 support. Includes backwards compatibility with 0.x types. ESM only.
0.x
5.0 - 6.0
LTS. Developed against older TypeScript versions and actively maintained under Long Term Support. Compatible with both ESM and CJS. Issues should be submitted to the Sinclair TypeBox repository.
Contribute
TypeBox 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.
sinclairzx81/typebox thuộc nhóm Frontend trên TopGit, cùng 2 topic GitHub. Trang Trending và Topics liệt kê các repo cùng số sao và cùng ngôn ngữ để so sánh.
Đọc thêm về sinclairzx81/typebox ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/sinclairzx81/typebox là nguồn chính thức.
sinclairzx81/typebox có bao nhiêu sao?
sinclairzx81/typebox có 7.0k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/sinclairzx81/typebox. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
sinclairzx81/typebox có phải mã nguồn mở không?
TopGit chưa ghi nhận license cho sinclairzx81/typebox. Phần lớn repo public trên GitHub là mã nguồn mở, nhưng điều khoản khác nhau từng repo — mở file LICENSE để xác nhận.
sinclairzx81/typebox có trang demo không?
Dự án có trang chủ ở https://sinclairzx81.github.io/typebox/. Tab "Readme" ở trang này thường có ảnh chụp và hướng dẫn bắt đầu nhanh.
sinclairzx81/typebox là gì?
sinclairzx81/typebox (sinclairzx81/typebox) là dự án TypeScript trên GitHub. Theo mô tả gốc: JSON Schema Type Builder with Static Type Resolution for TypeScript
sinclairzx81/typebox so với các dự án Frontend khác thế nào?
sinclairzx81/typebox được TopGit xếp vào nhóm Frontend, với 7.0k sao GitHub và viết bằng TypeScript. Xem trang chủ đề Frontend trên TopGit để so sánh với các dự án tương tự theo số sao và mức độ hoạt động.
Đọc đầy đủ README ở tab phía trên.
Vẫn đang phân vân về typebox?
Một cú bấm sẽ gửi câu hỏi kèm trang này cho AI — xem AI nói gì về typebox.