typescript

Solid

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.

Code & Development 17 stars 1 forks Updated yesterday MIT

Install

View on GitHub

Quality Score: 79/100

Stars 20%
42
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# 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...

Details

Author
dean0x
Repository
dean0x/devflow
Created
10 months ago
Last Updated
yesterday
Language
TypeScript
License
MIT

Bundled in these plugins

Similar Skills

Semantically similar based on skill content — not just same category