Files
typemap/example/index.ts
2025-01-26 22:03:51 +09:00

34 lines
1.4 KiB
TypeScript

import { TypeBox, Valibot, Zod } from '@sinclair/typemap'
// TypeScript Syntax Type
const S = `{
x: number,
y: number,
z: number
}`
// Construct Library Types from Syntax
const T = TypeBox(S) // const T: TObject<{
// x: TNumber,
// y: TNumber,
// z: TNumber
// }>
const V = Valibot(S) // const V: ObjectSchema<{
// x: NumberSchema<...>,
// y: NumberSchema<...>,
// z: NumberSchema<...>
// }, ...>
const Z = Zod(S) // const Z: ZodObject<{
// x: ZodNumber,
// y: ZodNumber,
// z: ZodNumber
// }, ...>
// Parse Syntax | Parse Value
const R = Zod('string | number').parse('...') // const R: string | number