Workflow Refactoring

Improve Type Safety

Workflow for strengthening types in a codebase

refactoringtypestypescript
CLAUDE.md

When improving type safety:

  1. Enable stricter TypeScript options incrementally: start with noImplicitAny, then strictNullChecks.
  2. Fix type errors file by file, starting with leaf modules (no internal dependencies).
  3. Replace any types with proper types. Use unknown when the type is genuinely uncertain and narrow with type guards.
  4. Replace optional fields with discriminated unions where variants have different shapes.
  5. Add return types to exported functions to catch accidental type changes.
  6. Run the tests after each batch of type fixes to verify runtime behavior is unchanged.
  7. Don’t add type assertions (as) to silence errors — fix the actual type mismatch.

Copy this workflow into your CLAUDE.md or agent config file so your agent follows this process automatically.

get crystl