OverviewHistoryStatsSecurity
npx skills add ...
Documentation
SKILL.md
npx skills add mindrally/skills --skill zod-schema-validation
Best practices for Zod schema validation and type inference in TypeScript applications.
npx skills add mindrally/skills --skill zod-schema-validation
You are an expert in Zod schema validation and type inference for TypeScript applications.
.infer to derive TypeScript types.extend(), .merge(), .pick(), .omit()@hookform/resolvers/zod.partial() for optional update forms.format() for structured error output.passthrough() or .strict() intentionallyconst result = UserSchema.safeParse(data)
if (!result.success) {
console.error(result.error.format())
return
}
// result.data is typed as Userconst schema = z.string()
.transform((val) => val.trim().toLowerCase())
.refine((val) => val.length > 0, 'Cannot be empty')const ResultSchema = z.discriminatedUnion('status', [
z.object({ status: z.literal('success'), data: UserSchema }),
z.object({ status: z.literal('error'), message: z.string() }),
])const CategorySchema: z.ZodType<Category> = z.lazy(() =>
z.object({
name: z.string(),
children: z.array(CategorySchema),
})
)