← ClaudeAtlas

typescriptlisted

This skill should be used when the user works with TypeScript files (.ts/.tsx), asks about "generics", "type guards", "utility types", "strict typing", "discriminated unions", or discusses type safety and inference. Provides patterns for Result types, exhaustive checks, branded types, and type-safe API contracts.
dean0x/devflow · ★ 19 · Code & Development · score 80
Install: claude install-skill dean0x/devflow
# TypeScript Patterns ## Iron Law > **UNKNOWN OVER ANY** > > Never use `any`. Use `unknown` with type guards instead. `any` disables TypeScript's > entire value proposition — if you need flexibility, use generics; if you need to handle > arbitrary data, use `unknown` and validate. `any` is giving up. [1, Item 43] ## When This Skill Activates - Working with TypeScript codebases or designing type-safe APIs - Using generics, type guards, branded types, or conditional types --- ## Type Safety Fundamentals ### Prefer Unknown Over Any [1, Item 43] Types are sets of values [1, Item 7]. `any` opts out entirely; `unknown` forces narrowing. ```typescript // BAD: disables all type checking [4][17] function parse(json: string): any { return JSON.parse(json); } // GOOD: unknown forces narrowing before use [1, Item 43] function parse(json: string): unknown { return JSON.parse(json); } if (isUser(data)) console.log(data.name); // type-safe after guard ``` ### Exhaustive Checks [1, Item 33][13] ```typescript type Status = 'pending' | 'running' | 'completed' | 'failed'; function handleStatus(status: Status): string { switch (status) { case 'pending': return 'Waiting...'; case 'running': return 'In progress...'; case 'completed': return 'Done!'; case 'failed': return 'Error occurred'; default: const _: never = status; throw new Error(`Unhandled: ${_}`); } } ``` --- ## Generic Patterns [2][6] ```typescript function first<T>(items: T[]): T | undefined { retu