File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -135,9 +135,13 @@ const emailSchema = z.email().meta({
135135</Tab >
136136<Tab value = " Zod Mini" >
137137``` ts
138- // no equivalent
139-
140-
138+ const emailSchema = z .email ().check (
139+ z .meta ({
140+ id: " email_address" ,
141+ title: " Email address" ,
142+ description: " Please enter a valid email address" ,
143+ })
144+ );
141145```
142146</Tab >
143147</Tabs >
@@ -181,11 +185,10 @@ emailSchema.meta({ description: "An email address" });
181185</Tab >
182186<Tab value = " Zod Mini" >
183187``` ts
184- // no equivalent
185-
186-
187-
188-
188+ const emailSchema = z .email ().check (z .describe (" An email address" ));
189+
190+ // equivalent to
191+ z .email ().check (z .meta ({ description: " An email address" }));
189192```
190193</Tab >
191194</Tabs >
Original file line number Diff line number Diff line change @@ -191,6 +191,10 @@ z.normalize();
191191z .trim ();
192192z .toLowerCase ();
193193z .toUpperCase ();
194+
195+ // metadata (registers schema in z.globalRegistry)
196+ z .meta ({ title: " ..." , description: " ..." });
197+ z .describe (" ..." );
194198```
195199
196200### ` .register() `
Original file line number Diff line number Diff line change @@ -3,3 +3,24 @@ import * as z from "zod";
33z . string ( ) . brand < "A" , "in" > ( ) ;
44z . string ( ) . brand < "A" , "out" > ( ) ;
55z . string ( ) . brand < "A" , "inout" > ( ) ;
6+
7+ const baseSchema = z . object ( {
8+ value : z . number ( ) ,
9+ allowsNegative : z . boolean ( ) ,
10+ somethingElse : z . string ( ) ,
11+ } ) ;
12+
13+ const refinement = z . refine < { value : number ; allowsNegative : boolean } > ( ( { value, allowsNegative } ) => {
14+ if ( allowsNegative ) {
15+ return true ;
16+ }
17+ return value >= 0 ;
18+ } ) ;
19+
20+ const schema = baseSchema . check ( refinement ) ;
21+
22+ const schemaB = baseSchema
23+ . safeOmit ( {
24+ somethingElse : true ,
25+ } )
26+ . check ( refinement ) ;
You can’t perform that action at this time.
0 commit comments