What problem does it solve?
Overusing the any type disables TypeScript's type checking, allowing runtime errors that should have been caught at compile time. This Skill teaches how to eliminate any type abuse by using unknown with proper type guards.
Core Features & Use Cases
any vs. unknown: Understand the critical distinction: any disables checks, unknown requires narrowing.
- Decision Flow: Guides on when to use specific types,
unknown, or (rarely) any for truly dynamic data.
- Type Guard Implementation: Learn to implement type guards (
typeof, instanceof, in, custom predicates) to safely narrow unknown values.
- Safe External Data Handling: Apply
unknown and validation to API responses, JSON parsing, and user input to prevent runtime crashes.
- Use Case: Refactor
src/data/api.ts to replace any return types from API calls with unknown, then add type guards to safely process the data, ensuring type safety and preventing runtime errors.
Quick Start
Replace any with unknown in the processExternalData function in src/utils/parser.ts, then add a type guard to safely access its properties.