Files
typemap/example/index.ts
sinclairzx81 6c5c187b4f Revision 0.8.11 (#21)
* Ensure Type Evaluation in Standard Schema Class Signature

* Version
2025-02-02 00:29:25 +09:00

47 lines
2.0 KiB
TypeScript

import { TypeBox, Valibot, Zod, Syntax, Compile } from '@sinclair/typemap'
// ------------------------------------------------------------------
// Syntax Types
// ------------------------------------------------------------------
const S = `{
x: number,
y: number,
z: number
}`
// ------------------------------------------------------------------
// Runtime Types
// ------------------------------------------------------------------
const T = TypeBox(S) // const T: TObject<{ ... }>
const V = Valibot(S) // const V: ObjectSchema<{ ... }, ...>
const Z = Zod(S) // const Z: ZodObject<{ ... }, ...>
// ------------------------------------------------------------------
// Reverse Syntax
// ------------------------------------------------------------------
const X = Syntax(Z) // const X: "{ x: number, y: number, z: number }"
// ------------------------------------------------------------------
// Compile
// ------------------------------------------------------------------
const C = Compile(X) // const C: Validator<TObject<{
// x: TNumber;
// y: TNumber;
// z: TNumber;
// }>>
// ------------------------------------------------------------------
// Validate | Standard
// ------------------------------------------------------------------
const R = C['~standard'].validate(null) // const R: StandardSchemaV1.Result<{
// x: number;
// y: number;
// z: number;
// }>