RecipesChapter 12: Type Development Strategies

Validating Data Types at Runtime with Zod

Recipe 12.5 from The TypeScript Cookbook

type PersonTypeIn = z.input<typeof Person>;
/*
type PersonTypeIn = {
  name: string;
  age: number;
  profession?: string | undefined;
  status: "active" | "inactive" | "registered";
};
*/

type PersonTypeOut = z.output<typeof Person>;
/*
type PersonTypeOut = {
  name: string;
  age: number;
  profession?: string | undefined;
  status: "active" | "inactive";
};
*/
Open in TypeScript Playground →