Skip to content

commandCode quality

Add Types

Adds precise type annotations to one file and fixes the checker errors that show up, without leaning on any or ignores.

npx workspacetemplates add add-types --tool claude-code

Writes 1 file to .claude/commands/

.claude/commands/add-types.md15 lines · 1.2 KBFile
---
description: Adds precise type annotations to one file and fixes the checker errors that show up, without leaning on any or ignores.
argument-hint: "[file to type]"
---

Add precise types to: $ARGUMENTS

1. Identify the language and the checker already configured (tsconfig.json, mypy.ini, pyproject.toml, pyright). Run it once and record the starting error count. Do not change checker settings.
2. Read the file and its callers and tests to learn the real shapes of parameters, return values and data structures. Check library types in node_modules or site-packages rather than guessing.
3. Annotate bottom-up: data shapes first (interfaces, TypedDict, dataclasses, enums, union literals), then function signatures, then variables the checker cannot infer.
4. Avoid `any`, `object`, `Any`, `as unknown as`, `# type: ignore` and `@ts-ignore`. If a value really is unknown, use `unknown` and narrow it.
5. Run the checker again and fix each error at its cause. If an error exposes a genuine bug, stop and describe it instead of silencing it.
6. Run the tests to make sure runtime behavior is unchanged.

Report starting versus ending error counts, the new types you defined, and any real bugs found. Do not edit other files without asking.

What it does

Loose types such as any or untyped dicts defeat the point of a type checker. This command annotates one file with specific types, reading call sites to learn what values really flow through.

It runs your configured checker, mypy, pyright or tsc, and fixes the errors at the source. If a real bug appears, it reports it rather than hiding it with a cast.

Example

you › /add-types src/api/client.ts

agent › tsc errors: 23 before, 0 after. Added interfaces ApiResponse<T>, RequestOptions, RetryPolicy; removed 9 any.
Found a bug: fetchUser() returns undefined on 404 but is typed as User; changed the return to User | null and updated 2 callers.
Tests pass.

Questions

Will it just use any to quiet errors?
No. Ignores, casts and any are off the table, and unclear values are narrowed instead.
Does it work for Python?
Yes, it uses mypy or pyright when configured and writes annotations, TypedDicts and dataclasses to match.
  • Add Error Handling

    CommandCode quality

    Free
  • Add Logging

    CommandCode quality

    Free
  • Extract Function

    CommandCode quality

    Free
  • Find Dead Code

    CommandCode quality

    Free