一键导入
zod-validation
Zod schema validation patterns. Activated when working with form validation, API response validation, or React Hook Form integration.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Zod schema validation patterns. Activated when working with form validation, API response validation, or React Hook Form integration.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
AGENTS.md authoring patterns. Activated when writing AI agent context files, working with agents.md or AGENTS.md.
Codebase onboarding guide. Activated when starting a new project analysis, requesting systematic codebase understanding, or running /onboard.
Feature-Sliced Design architecture patterns. Activated when working with FSD layers, slices, dependency rules, or structuring frontend code.
Modern React 19+ patterns. Activated when working with state management, Suspense, Compound Components, or React hooks.
React Query server state management patterns. Activated when applying Query Factory, queryOptions, or mutationOptions patterns.
Practical TypeScript patterns. Activated when working with type inference, utility types, generics, type guards, or type narrowing.
基于 SOC 职业分类
| name | zod-validation |
| description | Zod schema validation patterns. Activated when working with form validation, API response validation, or React Hook Form integration. |
Schema validation - core patterns only
import { z } from 'zod';
const userSchema = z.object({
name: z.string().min(1, 'Name is required'),
email: z.string().email('Invalid email format'),
age: z.number().optional(),
});
type User = z.infer<typeof userSchema>;
import { zodResolver } from '@hookform/resolvers/zod';
import { useForm } from 'react-hook-form';
const schema = z.object({
email: z.string().email(),
password: z.string().min(8),
});
type FormData = z.infer<typeof schema>;
function LoginForm() {
const { register, handleSubmit, formState: { errors } } = useForm<FormData>({
resolver: zodResolver(schema),
});
return (
<form onSubmit={handleSubmit(onSubmit)}>
<input {...register('email')} />
{errors.email && <span>{errors.email.message}</span>}
</form>
);
}
const apiResponseSchema = z.object({
id: z.string(),
created_at: z.string(),
});
// safeParse: returns result object instead of throwing
const result = apiResponseSchema.safeParse(response);
if (!result.success) {
console.error('Invalid response:', result.error.flatten());
return null;
}
return result.data;
const signupSchema = z
.object({
password: z.string().min(8),
confirmPassword: z.string(),
})
.refine((data) => data.password === data.confirmPassword, {
message: 'Passwords do not match',
path: ['confirmPassword'],
});
const schema = z.discriminatedUnion('type', [
z.object({ type: z.literal('email'), email: z.string().email() }),
z.object({ type: z.literal('phone'), phone: z.string() }),
]);
const userSchema = z.object({
id: z.string(),
name: z.string(),
email: z.string(),
});
const createUserSchema = userSchema.omit({ id: true });
const updateUserSchema = userSchema.partial().required({ id: true });
| Principle | Description |
|---|---|
| Single source of truth | Type and validation in one place via z.infer |
| safeParse for APIs | Use safeParse at system boundaries |
| Keep it simple | transform, coerce, preprocess only when truly needed |