Guide the design and implementation of Zod schemas following the project's Zod-first development approach, where schemas are defined before implementing business logic.
| Basic validation | Primitives | z.string().min(1) | | Domain safety | Branded types | transform((v) => v as EntitySlug) | | Multiple types | Discriminated union | z.discriminatedUnion('type', [...]) | | Cross-field rules | Refinement | .refine((data) => ...) | | Data normalization | Transform | .transform((v) => v.trim()) |
| Schema defined | No TS errors | npx tsc --noEmit | | Types inferred | z.infer works | Check type in IDE | | Validation works | safeParse tests | pnpm test |
Progetta schemi Zod seguendo lo sviluppo Zod-first. Crea schemi di convalida, tipi con marchio, unioni discriminate e trasformazioni. Deduce i tipi TypeScript dagli schemi. Trigger su: schema Zod, z.object, z.infer, convalida, tipi con marchio, unione discriminata, safeParse, perfezionamento. Fonte: saleor/configurator.