tail-recursive-generics
Installation
SKILL.md
Prefer Tail-Recursive Generic Types
Overview
TypeScript limits the depth of type instantiation to prevent infinite loops. When you hit "Type instantiation is excessively deep and possibly infinite," you need to refactor your recursive types to be tail-recursive. Using an accumulator pattern, you can write types that TypeScript can optimize, avoiding depth limits.
This skill is essential for type-level programming that processes large or deeply nested structures.
When to Use This Skill
- Getting "Type instantiation is excessively deep" errors
- Writing recursive generic types
- Processing large type structures
- Building type-level loops or iterations
- Deeply nested object transformations
The Iron Rule
Use accumulator patterns to make generic types tail-recursive. Pass accumulated results as type parameters rather than building up nested type structures.