From 80745238937adc06c5b4eab19ef273ca9f7f2de8 Mon Sep 17 00:00:00 2001 From: Colin McDonnell Date: Sat, 4 Mar 2023 01:38:59 -0800 Subject: [PATCH] Update readme --- README.md | 3 ++- deno/lib/README.md | 3 ++- playground.ts | 15 +++------------ 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 46bde68ca..0cde084cb 100644 --- a/README.md +++ b/README.md @@ -602,6 +602,7 @@ z.string().trim(); // trim whitespace z.string().datetime(); // defaults to UTC, see below for options z.string().ip(); // defaults to IPv4 and IPv6, see below for options ``` + @@ -1758,7 +1759,7 @@ This returns a `ZodEffects` instance. `ZodEffects` is a wrapper class that conta You can create a Zod schema for any TypeScript type by using `z.custom()`. This is useful for creating schemas for types that are not supported by Zod out of the box, such as template string literals. ```ts -const px = z.custom<`${number}px`>((val) => /^\d+px$/.test(val)); +const px = z.custom<`${number}px`>((val) => /^\d+px$/.test(val as string)); px.parse("100px"); // pass px.parse("100vw"); // fail ``` diff --git a/deno/lib/README.md b/deno/lib/README.md index 46bde68ca..0cde084cb 100644 --- a/deno/lib/README.md +++ b/deno/lib/README.md @@ -602,6 +602,7 @@ z.string().trim(); // trim whitespace z.string().datetime(); // defaults to UTC, see below for options z.string().ip(); // defaults to IPv4 and IPv6, see below for options ``` + @@ -1758,7 +1759,7 @@ This returns a `ZodEffects` instance. `ZodEffects` is a wrapper class that conta You can create a Zod schema for any TypeScript type by using `z.custom()`. This is useful for creating schemas for types that are not supported by Zod out of the box, such as template string literals. ```ts -const px = z.custom<`${number}px`>((val) => /^\d+px$/.test(val)); +const px = z.custom<`${number}px`>((val) => /^\d+px$/.test(val as string)); px.parse("100px"); // pass px.parse("100vw"); // fail ``` diff --git a/playground.ts b/playground.ts index 101654229..2b433a04c 100644 --- a/playground.ts +++ b/playground.ts @@ -1,13 +1,4 @@ import { z } from "./src"; -const baseCategorySchema = z.object({ - // - name: z.string(), - name: z.string().brand("CategoryName"), -}); - -type Category = z.infer & { - subcategories: Category[]; -}; - -const categorySchema: z.ZodType = baseCategorySchema.extend({ - subcategories: z.lazy(() => categorySchema.array()), -}); +const px = z.custom<`${number}px`>((val) => /^\d+px$/.test(val as string)); +px.parse("100px"); // pass +px.parse("100vw"); // fail