type-narrowing
Installation
SKILL.md
Understand Type Narrowing
Overview
Type narrowing is the process by which TypeScript refines a type from broad to more specific based on control flow.
Master narrowing to write cleaner code without type assertions, and to help TypeScript understand your logic.
When to Use This Skill
- Working with
Type | nullorType | undefined - Handling union types like
string | number - Processing discriminated unions (tagged unions)
- Getting "possibly undefined" errors
- Avoiding type assertions in conditionals