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.
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?
Action: Use unknown.
Reasoning: unknown is the type-safe counterpart to any. You cannot perform operations on it without first narrowing the type.