File tree 3 files changed +21
-28
lines changed
3 files changed +21
-28
lines changed Original file line number Diff line number Diff line change @@ -4630,7 +4630,11 @@ export type BRAND<T extends string | number | symbol> = {
4630
4630
export class ZodBranded <
4631
4631
T extends ZodTypeAny ,
4632
4632
B extends string | number | symbol
4633
- > extends ZodType < T [ "_output" ] & BRAND < B > , ZodBrandedDef < T > , T [ "_input" ] > {
4633
+ > extends ZodType <
4634
+ T [ "_output" ] & BRAND < B > ,
4635
+ ZodBrandedDef < T > ,
4636
+ T [ "_input" ] & BRAND < B >
4637
+ > {
4634
4638
_parse ( input : ParseInput ) : ParseReturnType < any > {
4635
4639
const { ctx } = this . _processInputParams ( input ) ;
4636
4640
const data = ctx . data ;
Original file line number Diff line number Diff line change 1
1
import { z } from "./src" ;
2
- const example1 = z . custom < number > ( ( x ) => typeof x === "number" ) ;
3
- example1 . parse ( "asdf" ) ;
4
- // const example1 = z
5
- // .custom<number>(
6
- // (x) => {
7
- // console.log(`custom`);
8
- // console.log(x);
9
- // return typeof x === "number";
10
- // },
11
- // {},
12
- // true
13
- // )
14
- // .transform((x) => {
15
- // console.log(`transform`);
16
- // console.log(x);
17
- // return String(x);
18
- // })
19
- // .refine((x) => {
20
- // console.log(`refine`);
21
- // console.log(x);
22
- // console.log(typeof x); // prints 'Object'
23
- // console.log("I get called even though I shouldn't!!!");
24
- // return true;
25
- // })
26
- // .safeParse({}); //will fail because it is not a number
2
+ const baseCategorySchema = z . object ( {
3
+ // - name: z.string(),
4
+ name : z . string ( ) . brand ( "CategoryName" ) ,
5
+ } ) ;
27
6
28
- // console.log(example1.success); // false (like it should be)
7
+ type Category = z . infer < typeof baseCategorySchema > & {
8
+ subcategories : Category [ ] ;
9
+ } ;
10
+
11
+ const categorySchema : z . ZodType < Category > = baseCategorySchema . extend ( {
12
+ subcategories : z . lazy ( ( ) => categorySchema . array ( ) ) ,
13
+ } ) ;
Original file line number Diff line number Diff line change @@ -4630,7 +4630,11 @@ export type BRAND<T extends string | number | symbol> = {
4630
4630
export class ZodBranded <
4631
4631
T extends ZodTypeAny ,
4632
4632
B extends string | number | symbol
4633
- > extends ZodType < T [ "_output" ] & BRAND < B > , ZodBrandedDef < T > , T [ "_input" ] > {
4633
+ > extends ZodType <
4634
+ T [ "_output" ] & BRAND < B > ,
4635
+ ZodBrandedDef < T > ,
4636
+ T [ "_input" ] & BRAND < B >
4637
+ > {
4634
4638
_parse ( input : ParseInput ) : ParseReturnType < any > {
4635
4639
const { ctx } = this . _processInputParams ( input ) ;
4636
4640
const data = ctx . data ;
You can’t perform that action at this time.
0 commit comments