define-types-before-implementation
Installation
SKILL.md
Summary
Always write Types, Interfaces, or Structs before writing the implementation logic. Treat types as the contract or specification of the code.
Rationale
- Contract-Driven: Defining types first clarifies the "What" before the "How", preventing logic from becoming convoluted to handle undefined states.
- Error Isolation: If a type error occurs during implementation, it signals that the implementation logic is flawed relative to the design. Fixing the implementation is the correct path, not loosening the type (e.g., to
any). - No
any: Writing types first eliminates the need for temporaryanycasts often used when "hacking together" a solution.
Guidance
- Rule: Start by defining the shape.
- TypeScript: Define
interface/type/ function signatures. - Go: Define
structandinterface. - Java: Define
interface/classsignatures.
- TypeScript: Define
- Process:
- Write the Type definition.
- Use the Type in the function signature.
- Write the body to satisfy the Type.
- Strictness: Do not change the Type just to make the Implementation easier (unless the design itself was wrong). Do not use
anyorinterface{}to bypass the contract.