Created
January 17, 2022 14:30
-
-
Save iskenxan/a165ced69423d5287b28bd7d2abc7ec5 to your computer and use it in GitHub Desktop.
Typescript schema validation with zod
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { z } from "zod"; | |
const stringSchema = z.string().nonempty().min(8).max(32); | |
stringSchema.parse(""); | |
stringSchema.parse(""); // throws an exception | |
stringSchema.parse("I am a valid password"); // returns "I am a valid password" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment