GitHub Copilot prompt to migrate JavaScript to TypeScript
Converting a codebase to TypeScript in one pass produces a wall of any and a broken build. This prompt sets GitHub Copilot up for an incremental migration, strict mode on converted files only, leaf directories first, so every step compiles and your test suite stays green from the first rename.
Last updated
Migrate this package from JavaScript to TypeScript one directory at a time, starting with src/utils because nothing imports it from outside. First add tsconfig.json with allowJs true, checkJs false, and strict true so converted files are held to the full standard while the rest compiles untouched. Rename each file to .ts, type exported function signatures explicitly, and let inference handle locals. Where a shape crosses module boundaries, lift it into src/types.ts rather than repeating inline object types. Do not change any runtime behavior, no logic edits, no reordering, and flag any spot where an implicit any hides a probable bug instead of silently casting. Never use ts-ignore, prefer unknown plus a narrowing check. After each directory, I will run npx tsc --noEmit and the existing test suite, and the diff must show only renames and type annotations.
Same task in other tools
Questions about this prompt
Why convert leaf directories like src/utils first?
Files nothing else imports can be typed without pushing errors into unconverted code. Working from the leaves inward keeps npx tsc --noEmit passing after every directory instead of only at the very end.
What changes for a React codebase?
The same order applies, but move shared prop and hook return shapes into src/types.ts early because many components consume them, and rename .jsx files to .tsx so JSX keeps compiling.
Copilot quiets errors with as any casts. How do I stop it?
Reject those hunks in the diff review and re-prompt asking it to explain each error it tried to cast away. The explanations usually reveal either a real bug or a missing type in types.ts.