1
- import * as v from 'valibot'
2
- import { checkUserA , checkUserB , checkUserC } from './utils'
1
+ import { number , object , optional , parse , safeParse , string , type InferInput , type InferOutput } from 'valibot'
2
+ import { checkUserA , checkUserB , checkUserC } from './utils.ts '
3
3
4
- const userSchema = v . object ( {
5
- name : v . string ( ) ,
6
- age : v . optional ( v . number ( ) , 42 ) ,
4
+ const userSchema = object ( {
5
+ name : string ( ) ,
6
+ age : optional ( number ( ) , 42 ) ,
7
7
} )
8
8
9
- export type User = v . InferOutput < typeof userSchema >
9
+ export type User = InferOutput < typeof userSchema >
10
10
11
- export type UserInput = v . InferInput < typeof userSchema >
11
+ export type UserInput = InferInput < typeof userSchema >
12
12
13
- const userA = v . parse ( userSchema , { name : "Jordan" } )
13
+ const userA = parse ( userSchema , { name : "Jordan" } )
14
14
checkUserA ( userA )
15
15
16
16
function createUser ( input : UserInput ) {
17
- const result = v . safeParse ( userSchema , input )
17
+ const result = safeParse ( userSchema , input )
18
18
if ( ! result . success ) return userA
19
19
return result . output
20
20
}
@@ -26,4 +26,4 @@ checkUserB(userB)
26
26
const userC = createUser ( { name : "Romain" , age : "35" } )
27
27
checkUserC ( userC )
28
28
29
- console . log ( 'All tests passed successfully.' )
29
+ console . log ( 'All tests passed successfully.' )
0 commit comments