-
Notifications
You must be signed in to change notification settings - Fork 141
/
index.ts
26 lines (21 loc) · 930 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { Type, TSchema, Static, StaticDecode, TypeGuard } from '@sinclair/typebox'
import { Value, ValueError, ValueErrorType, TransformDecodeError } from '@sinclair/typebox/value'
import { TypeCompiler } from '@sinclair/typebox/compiler'
import { Kind, TypeRegistry, FormatRegistry } from '@sinclair/typebox'
const UnsafeByte = Type.Unsafe<number>({ type: 'byte' })
const Byte = Type.Refine(UnsafeByte)
.Check((value) => typeof value === 'number')
.Check((value) => !isNaN(value), { message: 'Must not be NaN', x: 100 })
.Check((value) => value >= 0, { message: 'Must be greater than 0' })
.Check((value) => value < 256, { message: 'Must be something' })
.Done()
const A = Type.Object({
x: Byte,
y: Byte,
z: Byte,
})
console.dir(A, { depth: 100 })
console.log(TypeCompiler.Code(A))
console.log(Value.Errors(Byte, 'asdsa').Take(10))
// Todo: Error Tests
// Todo: Investigate Error Propogation for Refinements