BoilerPrompt
Claude Code

Claude Code prompt to migrate JavaScript to TypeScript

A TypeScript migration lives or dies on whether the build stays green mid-flight. Because Claude Code runs tsc and your test suite itself between batches, it catches conversion mistakes at file ten instead of file two hundred. The prompt also preserves git history with git mv, which most automated codemods throw away.

Last updated

Prompt
Migrate this JavaScript codebase to TypeScript incrementally, keeping the app buildable after every step. First add tsconfig.json with allowJs and checkJs enabled and strict off, run the compiler, and report the baseline error count. Then convert files in dependency order, leaf modules first: rename with git mv so history survives, add explicit types for exported functions, and use unknown instead of any at module boundaries. Do not change runtime behavior; if a bug surfaces during typing, note it in a TODO comment instead of fixing it silently. After each batch of ten files, run tsc and the existing test suite and stop if either fails. Once every file is converted, turn on strict, fix what breaks, and give me the final tsc output plus a list of any remaining any types with file and line.

Same task in other tools

Questions about this prompt

Why start with strict mode off?

Turning strict on across an unconverted codebase produces an error wall with no signal. The allowJs plus checkJs baseline gives a number that shrinks batch by batch, and strict lands at the end as a final gate over already-typed files.

The repo is too large for one session. Can this resume?

Yes, the state lives in the repo itself: converted files, tsconfig, and the remaining .js files. Point Claude Code at the next directory and repeat the batch loop; the run-tsc-and-tests checkpoint works the same from any starting point.

The diff shows behavior changes mixed in with types. What now?

The prompt forbids silent fixes for exactly this reason. Ask the agent to revert the file, re-apply types only, and leave a TODO where it saw the suspect logic, then confirm with git diff that only annotations changed.

Related prompts