diff --git a/deno/lib/types.ts b/deno/lib/types.ts index 624a1e3e6..57f9dbb9a 100644 --- a/deno/lib/types.ts +++ b/deno/lib/types.ts @@ -4630,7 +4630,11 @@ export type BRAND = { export class ZodBranded< T extends ZodTypeAny, B extends string | number | symbol -> extends ZodType, ZodBrandedDef, T["_input"]> { +> extends ZodType< + T["_output"] & BRAND, + ZodBrandedDef, + T["_input"] & BRAND +> { _parse(input: ParseInput): ParseReturnType { const { ctx } = this._processInputParams(input); const data = ctx.data; diff --git a/playground.ts b/playground.ts index 2a85b5a3c..101654229 100644 --- a/playground.ts +++ b/playground.ts @@ -1,28 +1,13 @@ import { z } from "./src"; -const example1 = z.custom((x) => typeof x === "number"); -example1.parse("asdf"); -// const example1 = z -// .custom( -// (x) => { -// console.log(`custom`); -// console.log(x); -// return typeof x === "number"; -// }, -// {}, -// true -// ) -// .transform((x) => { -// console.log(`transform`); -// console.log(x); -// return String(x); -// }) -// .refine((x) => { -// console.log(`refine`); -// console.log(x); -// console.log(typeof x); // prints 'Object' -// console.log("I get called even though I shouldn't!!!"); -// return true; -// }) -// .safeParse({}); //will fail because it is not a number +const baseCategorySchema = z.object({ + // - name: z.string(), + name: z.string().brand("CategoryName"), +}); -// console.log(example1.success); // false (like it should be) +type Category = z.infer & { + subcategories: Category[]; +}; + +const categorySchema: z.ZodType = baseCategorySchema.extend({ + subcategories: z.lazy(() => categorySchema.array()), +}); diff --git a/src/types.ts b/src/types.ts index bc8ca713d..34e541a9f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -4630,7 +4630,11 @@ export type BRAND = { export class ZodBranded< T extends ZodTypeAny, B extends string | number | symbol -> extends ZodType, ZodBrandedDef, T["_input"]> { +> extends ZodType< + T["_output"] & BRAND, + ZodBrandedDef, + T["_input"] & BRAND +> { _parse(input: ParseInput): ParseReturnType { const { ctx } = this._processInputParams(input); const data = ctx.data;