Typescript

Use when: write or review TypeScript that maximizes type safety without fighting the compiler.

kimtth 79de263 1.0 KB Updated

File contents

Goal: catch errors at compile time with types that aid, not obstruct.

Use for:

  • new TypeScript code or migrating from JavaScript
  • reviewing type usage, strictness, and module structure
  • removing any, casts, and unsafe escape hatches

Workflow:

  1. Enable strict mode and treat its warnings as errors.
  2. Type module and function boundaries; let locals infer.
  3. Model data with unions and interfaces, not loose objects.
  4. Narrow with type guards before using union members.
  5. Replace any with unknown and narrow deliberately.
  6. Verify with tsc, eslint, and tests.

Idioms:

  • satisfies to validate without widening
  • discriminated unions for variant data
  • readonly and const assertions for immutability
  • utility types (Pick, Omit, Partial, Record)

Rules:

  • strict mode on; no implicit any
  • avoid type assertions; prove the type instead
  • do not export inferred wide types from APIs
  • a type that lies is worse than no type

kimtth/agent-skill-100-lines-or-less/tree/main/skills/typescript commit 79de263bc6

Frequently asked questions

npx skillmds@latest add kimtth/typescript