1- import Compile from 'typebox/compile'
2- import System from 'typebox/system'
3- import Guard from 'typebox/guard'
4- import Format from 'typebox/format'
5- import Schema from 'typebox/schema'
6- import Value from 'typebox/value'
71import Type from 'typebox'
82
9- // ------------------------------------------------------------------
10- // Settings
11- // ------------------------------------------------------------------
3+ const { A } = Type . Script ( `
4+ type A = {
5+ x: number
6+ y: number
7+ } & if { x: 1 } then { y: 2 } else
8+ if { x: 2 } then { y: 3 } else
9+ never
10+ ` )
1211
13- System . Settings . Set ( { enumerableKind : false } )
1412
15- // ------------------------------------------------------------------
16- // Guard
17- // ------------------------------------------------------------------
13+ type A = Type . Static < typeof A >
1814
19- const A = Guard . GraphemeCount ( 'type-📦' ) // 6
20- const B = Guard . HasPropertyKey ( { x : 1 } , 'x' ) // true
15+ function test ( value : Type . Static < typeof A > ) { }
2116
22- // ------------------------------------------------------------------
23- // Type
24- // ------------------------------------------------------------------
17+ test ( { x : 1 , y : 2 } ) // ok
18+ test ( { x : 2 , y : 3 } ) // ok
2519
26- const T = Type . Object ( {
27- x : Type . Number ( ) ,
28- y : Type . Number ( ) ,
29- z : Type . Number ( )
30- } )
20+ test ( { x : 1 , y : - 1 } ) // error: Type '-1' is not assignable to type '2 | 3'
21+ test ( { x : 2 , y : - 1 } ) // error: Type '-1' is not assignable to type '2 | 3'
3122
32- // ------------------------------------------------------------------
33- // Script
34- // ------------------------------------------------------------------
3523
36- const S = Type . Script ( { T } , `{
37- [K in keyof T]: T[K] | null
38- }` )
3924
40- // ------------------------------------------------------------------
41- // Infer
42- // ------------------------------------------------------------------
25+ console . dir ( A )
4326
44- type T = Type . Static < typeof T >
45- type S = Type . Static < typeof S >
4627
47- // ------------------------------------------------------------------
48- // Parse
49- // ------------------------------------------------------------------
50-
51- const R = Value . Parse ( T , { x : 1 , y : 2 , z : 3 } )
52-
53- // ------------------------------------------------------------------
54- // Compile
55- // ------------------------------------------------------------------
56- const C = Compile ( S )
57-
58- const X = C . Parse ( { x : 1 , y : 2 , z : 3 } )
59-
60- // ------------------------------------------------------------------
61- // Format
62- // ------------------------------------------------------------------
63-
64- const E = Format . IsEmail ( 'user@domain.com' )
65-
66- // ------------------------------------------------------------------
67- // Schema
68- // ------------------------------------------------------------------
69-
70- const D = Schema . Parse ( { const : 'hello' } , 'hello' )
0 commit comments