sinclairzx81/typebox là dự án TypeScript với 6.9k 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(), // properties: {
z: Type.Number() // x: { type: 'number' },
}) // y: { type: 'number' },
// z: { type: 'number' }
// },
// required: ['x', 'y', 'z']
// }
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 offers a set of types used to construct JSON Schema compliant schematics as well as a set of extended types used to model constructs native to the JavaScript language. The schematics produced by TypeBox can be passed directly to any JSON Schema 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'
// Math Module
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 }
`)
// Graphics Module
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
TypeBox includes a high-performance JIT compiler that supports JSON Schema Draft 3 through to 2020-12. It is designed to be a lightweight industry-grade alternative to Ajv and offers improved compilation and validation performance. It also provides 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 either TypeBox types or native JSON Schema.
Compiled validator instances provide functions to Check and Parse values.
// 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
// }
Coverage
JSON Schema Test Suite | JSON Schema Compliance Suite
TypeBox supports all major JSON Schema draft versions and tracks compliance against the official JSON Schema Test Suite. It also maintains a separate JavaScript compliance suite to track ecosystem adoption as JSON Schema moves toward the V1 candidate. The following table shows TypeBox specification coverage.
Spec
3
4
6
7
2019-09
2020-12
v1
additionalItems
✅
✅
✅
✅
✅
-
-
additionalProperties
✅
✅
✅
✅
✅
✅
✅
allOf
-
✅
✅
✅
✅
✅
✅
anchor
-
-
-
-
✅
✅
✅
anyOf
-
✅
✅
✅
✅
✅
✅
boolean_schema
-
-
✅
✅
✅
✅
✅
const
-
-
✅
✅
✅
✅
✅
contains
-
-
✅
✅
✅
✅
✅
content
-
-
-
-
✅
✅
✅
default
✅
✅
✅
✅
✅
✅
✅
dependencies
17/18
✅
✅
✅
-
-
-
dependentRequired
-
-
-
-
✅
✅
✅
dependentSchemas
-
-
-
-
✅
✅
✅
dynamicRef
-
-
-
-
-
40/44
21/27
enum
14/16
✅
✅
✅
✅
✅
✅
exclusiveMaximum
-
-
✅
✅
✅
✅
✅
exclusiveMinimum
-
-
✅
✅
✅
✅
✅
if-then-else
-
-
-
✅
✅
✅
✅
infinite-loop-detection
✅
✅
✅
✅
✅
✅
✅
items
✅
✅
✅
✅
✅
✅
✅
maxContains
-
-
-
-
✅
✅
✅
maximum
13/14
13/14
✅
✅
✅
✅
✅
maxItems
✅
✅
✅
✅
✅
✅
✅
maxLength
✅
✅
✅
✅
✅
✅
✅
maxProperties
-
✅
✅
✅
✅
✅
✅
minContains
-
-
-
-
✅
✅
✅
minimum
12/13
16/17
✅
✅
✅
✅
✅
minItems
✅
✅
✅
✅
✅
✅
✅
minLength
✅
✅
✅
✅
✅
✅
✅
minProperties
-
✅
✅
✅
✅
✅
✅
multipleOf
-
✅
✅
✅
✅
✅
✅
not
-
✅
✅
✅
✅
✅
✅
oneOf
-
✅
✅
✅
✅
✅
✅
pattern
✅
✅
✅
✅
✅
✅
✅
patternProperties
✅
✅
✅
✅
✅
✅
✅
prefixItems
-
-
-
-
-
✅
✅
properties
✅
✅
✅
✅
✅
✅
✅
propertyNames
-
-
✅
✅
✅
✅
✅
recursiveRef
-
-
-
-
✅
-
-
ref
22/27
37/45
67/70
75/78
79/81
77/79
78/79
required
3/4
✅
✅
✅
✅
✅
✅
type
73/80
✅
✅
✅
✅
✅
✅
unevaluatedItems
-
-
-
-
✅
✅
70/71
unevaluatedProperties
-
-
-
-
✅
✅
128/129
uniqueItems
✅
✅
✅
✅
✅
✅
✅
Performance
TypeBox tracks comparative performance against AJV8 as the de facto performance standard. For broader comparative benchmarks, refer to the community maintained projects below.
Runtime Benchmarks | Schema Benchmarks
The following table shows compilation performance for various JSON Schema structures. These benchmarks measure the time required to JIT compile schematics, with faster compilation resulting in faster application startup.
The following tables shows validation performance for various JSON Schema structures. These benchmarks measure overall validation throughput for JIT 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ó 6.9k 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 6.9k 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.