Cursor prompt to migrate JavaScript to TypeScript
An incremental migration plan the agent executes batch by batch instead of attempting a risky whole-repo rewrite. Cursor runs tsc and your tests in the terminal after every batch, so a bad conversion is caught within ten files. You end with strict mode on and a greppable list of deliberately deferred types.
Last updated
Migrate this repo from JavaScript to TypeScript incrementally, not in one pass. Start by adding tsconfig.json with allowJs true and strict false, wire the build so mixed JS and TS compiles, and commit that as the baseline. Then convert files in dependency order, leaf utilities first, entry points last, renaming to .ts or .tsx and typing exported function signatures fully while letting locals stay inferred. Never use any to silence an error, use unknown plus a narrowing check or a TODO type alias I can grep for. Do not change runtime behavior, if a refactor is tempting, leave a comment instead. After each batch of about ten files, run tsc --noEmit and the test suite in the terminal and stop if either fails. Finish by flipping strict to true and reporting every remaining error grouped by file.
Same task in other tools
Questions about this prompt
The repo has hundreds of files. Can this finish in one session?
No, and it should not try. Each batch ends with a passing tsc and test run, which makes a clean stopping point. Next session, point the agent at the remaining .js files and it resumes under the same rules.
What about npm dependencies without type definitions?
Ask for @types packages where they exist and one ambient.d.ts declaring the rest as modules, instead of ts-ignore comments scattered through imports. That keeps the debt in a single file you can burn down later.
How do I catch the agent changing behavior while it types?
Review each batch diff for anything that is not a rename, an annotation, or an import fix, and reject those hunks. The comment-instead-of-refactor rule also gives you a grep target for rewrites it wanted to make and deferred.