← ClaudeAtlas

typescript-patternslisted

Use for TypeScript in an existing project when choosing idiomatic types, discriminated unions, typed errors, promises, concurrency, or async design.
lawzava/megapowers · ★ 4 · AI & Automation · score 73
Install: claude install-skill lawzava/megapowers
# TypeScript Patterns Idioms for correct, readable TypeScript. Each is a default, not a law. > **Measured:** in this repo's skill-effect study, current frontier *and* small > Claude models already write correct versions of common concurrency/data > patterns without pattern skills (zero correctness headroom; see > `evals/RESULTS.md`). The value here is consistency of *design choices* > (types at boundaries, error shape, module layout), not single-shot > correctness. ## Types - Turn on `strict` and `noUncheckedIndexedAccess`. Let inference handle locals; type the public boundaries (exported functions, request/response, module APIs). - Prefer `unknown` over `any` at a boundary, then narrow. `any` disables the checker and hides bugs; if you must, isolate it behind a typed function. - Model closed sets with a **discriminated union** (a literal `kind` field) and switch on it exhaustively — add a `never` default so the compiler flags a missing case: ```ts type Shape = { kind: 'circle'; r: number } | { kind: 'rect'; w: number; h: number } function area(s: Shape): number { switch (s.kind) { case 'circle': return Math.PI * s.r ** 2 case 'rect': return s.w * s.h default: { const _exhaustive: never = s; return _exhaustive } } } ``` - Derive types from a single source of truth: `z.infer<typeof Schema>` for validated data, `as const` + `typeof` for literal config. Don't hand-maintain a parallel type. ## Errors - For an *expected* failure (a lookup miss, a