conditional-types-over-overloads
Installation
SKILL.md
Prefer Conditional Types to Overload Signatures
Overview
When a function's return type depends on its input type, you might reach for overload signatures. However, conditional types often provide a better solution. Unlike overloads, which are checked independently, conditional types distribute over unions and can be analyzed as a single expression. This makes them more powerful for handling union inputs and results in more maintainable type declarations.
Understanding when to use conditional types versus overloads is key to writing flexible, correct type signatures.
When to Use This Skill
- Function return type depends on input type
- Function accepts union types
- Considering multiple overload signatures
- Need precise return types based on inputs
- Building type utilities that transform types
The Iron Rule
Prefer conditional types to overloaded signatures. Conditional types distribute over unions and provide more precise, maintainable type declarations.