Improve Type Safety
Workflow for strengthening types in a codebase
CLAUDE.md
When improving type safety:
- Enable stricter TypeScript options incrementally: start with
noImplicitAny, thenstrictNullChecks. - Fix type errors file by file, starting with leaf modules (no internal dependencies).
- Replace
anytypes with proper types. Useunknownwhen the type is genuinely uncertain and narrow with type guards. - Replace optional fields with discriminated unions where variants have different shapes.
- Add return types to exported functions to catch accidental type changes.
- Run the tests after each batch of type fixes to verify runtime behavior is unchanged.
- 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.