Skip to content

Commit 56c5dd0

Browse files
docs: add Zod type inference guidance to AGENTS.md
Always use z.infer to derive TypeScript types from Zod schemas instead of manually defining duplicate types. Co-authored-by: Chris Bongers <rebelchris@users.noreply.github.com>
1 parent a237f8b commit 56c5dd0

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

AGENTS.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,33 @@ import ControlledTextarea from '@dailydotdev/shared/src/components/fields/Contro
131131
import ControlledSwitch from '@dailydotdev/shared/src/components/fields/ControlledSwitch';
132132
```
133133

134+
**IMPORTANT - Zod Type Inference:**
135+
- **ALWAYS use `z.infer` to derive TypeScript types from Zod schemas**
136+
- **NEVER manually define types that duplicate Zod schema structure**
137+
138+
```typescript
139+
// ❌ WRONG: Manual type definition that duplicates schema
140+
const userSchema = z.object({
141+
name: z.string(),
142+
age: z.number(),
143+
});
144+
145+
interface User {
146+
name: string;
147+
age: number;
148+
}
149+
150+
// ✅ RIGHT: Infer type from schema
151+
const userSchema = z.object({
152+
name: z.string(),
153+
age: z.number(),
154+
});
155+
156+
export type User = z.infer<typeof userSchema>;
157+
```
158+
159+
This ensures type safety, reduces duplication, and keeps types automatically in sync with schemas.
160+
134161
## Quick Commands
135162

136163
```bash

0 commit comments

Comments
 (0)