Skip to content

Instantly share code, notes, and snippets.

@iskenxan
Created January 17, 2022 14:30
Show Gist options
  • Save iskenxan/a165ced69423d5287b28bd7d2abc7ec5 to your computer and use it in GitHub Desktop.
Save iskenxan/a165ced69423d5287b28bd7d2abc7ec5 to your computer and use it in GitHub Desktop.
Typescript schema validation with zod
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