use-utility-types-for-dry-types
Installation
SKILL.md
Summary
Do not manually redefine interfaces that are subsets or variations of existing types. Use TypeScript's built-in Utility Types (Pick, Omit, Partial, Required, ReturnType) to derive new types from a "Single Source of Truth".
Rationale
- Maintenance: When the source type changes (e.g., adding a field to
User), derived types update automatically. - Consistency: Prevents subtle bugs where a DTO and the Domain Model diverge over time.
- Intent: Seeing
Pick<User, 'id' | 'email'>clearly communicates "This is just a user ID and email" better than a genericUserDTO.
Guidance
- Derive Downwards: Define the "full" entity (e.g., database model) first, then derive input/output types from it.
- Avoid Duplication: If you catch yourself copy-pasting properties, stop and use a Utility Type.
- Composition: You can combine them:
Partial<Pick<User, 'name'>>.