| name | ts-no-any |
| description | Use when implementing or refactoring TypeScript code to ensure strict type safety and avoid the 'any' type. Provides strategies for unknown types, generics, and type guards. |
TypeScript Strict Typing (No-Any)
This skill enforces high-quality TypeScript implementation by eliminating the any type in favor of safer, more explicit alternatives.
Core Principles
- No
any by default: Treat any as a bug. If you can't type it yet, use unknown.
- Type over Comment: Use the type system to document behavior instead of comments.
- Narrow Early: Convert broad types (
unknown, string, etc.) to specific types as close to the I/O boundary as possible.
Workflow: Replacing any
When you encounter a situation where any feels tempting, follow this decision tree:
1. Is the structure truly unknown?
2. Is the type dependent on the caller?
3. Is it a complex object from an API?
- Action: Define an
interface or type. Use Record<string, unknown> for dictionary-like objects.
- Reasoning: Provides autocomplete and build-time validation.
4. Are you handling union types?
Quality Checklist
Prohibited Patterns
as any type assertions.
any[] for arrays (use unknown[] or a specific interface).
- Function signatures using
any for arguments or return values.