Skip to content

commandCode quality

Fix Type Errors

Runs your type checker and fixes each reported error at its root cause, never with casts, any or suppression comments.

npx workspacetemplates add fix-type-errors --tool claude-code

Writes 1 file to .claude/commands/

.claude/commands/fix-type-errors.md14 lines · 1.2 KBFile
---
description: Runs your type checker and fixes each reported error at its root cause, never with casts, any or suppression comments.
argument-hint: "[optional file or error code]"
---

Fix the type errors in this project. Scope: $ARGUMENTS (everything if empty).

1. Find the checker command in package.json scripts, pyproject, tox or CI config (`tsc --noEmit`, `mypy .`, `pyright`, `go vet`, `cargo check`). Run it and save the full error list with the count.
2. Group errors by root cause: a changed library type, a wrong interface, a missing null check, an outdated mock. Fix the root first and re-run, since many errors usually vanish together.
3. Fix each one with a correct type or a real guard. Never add `as any`, `as unknown as`, `!` non-null assertions, `@ts-ignore`, `@ts-expect-error` or `# type: ignore`, and never loosen the compiler options.
4. If the fix would require changing behavior, or the error reveals a genuine bug, stop on that item and describe it with the file and line.
5. Re-run the checker until clean or until only the stopped items remain. Then run the tests.

Report the count before and after, the root causes found, any bugs, and the files changed. Ask before changing any public type that other packages consume.

What it does

A wall of type errors tempts people to add casts until it goes quiet. This command works through them properly, grouping errors by cause, since one wrong type often explains dozens of messages.

Where an error points at a real bug, it tells you. The checker output at the end is the proof that the work is done.

Example

you › /fix-type-errors

agent › tsc --noEmit: 87 errors before, 0 after. Root causes: 61 from the upgraded @types/express Request, 18 missing null checks, 8 stale test mocks.
Real bug: orders.ts:140 reads item.price before it is loaded; added the guard.
Tests pass.

Questions

Why not just add casts?
Casts hide the mismatch, so the bug moves to runtime. This command fixes the type or the code that disagrees with it.
What if a fix needs behavior changes?
It stops on that error, explains it and waits, because that decision belongs to you.
  • Add Error Handling

    CommandCode quality

    Free
  • Add Logging

    CommandCode quality

    Free
  • Add Types

    CommandCode quality

    Free
  • Extract Function

    CommandCode quality

    Free