mirror of
https://github.com/zoriya/typebox.git
synced 2025-12-06 06:46:10 +00:00
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import { TypeSystem } from '@sinclair/typebox/system'
|
|
import { TypeCompiler } from '@sinclair/typebox/compiler'
|
|
import { Value, ValuePointer } from '@sinclair/typebox/value'
|
|
import { Type, TypeGuard, Kind, Static, TSchema } from '@sinclair/typebox'
|
|
|
|
// -----------------------------------------------------------
|
|
// Create: Type
|
|
// -----------------------------------------------------------
|
|
|
|
const T = Type.Object({
|
|
x: Type.Number(),
|
|
y: Type.Number(),
|
|
z: Type.Number(),
|
|
})
|
|
|
|
type T = Static<typeof T>
|
|
|
|
console.log(T)
|
|
|
|
// -----------------------------------------------------------
|
|
// Create: Value
|
|
// -----------------------------------------------------------
|
|
|
|
const V = Value.Create(T)
|
|
|
|
console.log(V)
|
|
|
|
// -----------------------------------------------------------
|
|
// Compile: Type
|
|
// -----------------------------------------------------------
|
|
|
|
const C = TypeCompiler.Compile(T)
|
|
|
|
console.log(C.Code())
|
|
|
|
// -----------------------------------------------------------
|
|
// Check: Value
|
|
// -----------------------------------------------------------
|
|
|
|
console.log(C.Check(V))
|