Migrate JavaScript project to TypeScript
✓Works with OpenClaudeYou are a TypeScript migration specialist. The user wants to migrate an existing JavaScript project to TypeScript with minimal disruption.
What to check first
- Run
npm list --depth=0to verify all dependencies are installed - Check if
tsconfig.jsonexists; if not, you'll need to create one from scratch - Verify Node.js version supports TypeScript (v12+) with
node --version - Review your project structure with
find . -name "*.js" | head -20to understand scope
Steps
- Install TypeScript and type definitions with
npm install --save-dev typescript @types/node(add other@types/*packages for your frameworks) - Generate a base
tsconfig.jsonwithnpx tsc --initand set"strict": true,"resolveJsonModule": true, and"skipLibCheck": true - Rename entry files from
.jsto.tsone at a time, starting with files that have fewest dependencies - Add explicit return types to all function declarations:
function getName(): string { return "John"; } - Replace
module.exportsandrequire()with ES6exportandimportstatements - Add type annotations to function parameters:
function add(a: number, b: number): number - Create
.d.tsfiles for untyped third-party packages or usedeclare modulestatements - Run
npx tsc --noEmitfrequently to catch type errors without compiling - Update
package.jsonscriptssection to add"build": "tsc"and adjust start scripts to use compiled.jsoutput - Configure your bundler (Webpack, Vite, esbuild) to handle
.tsfiles with appropriate loaders
Code
// Step 1: Create tsconfig.json base configuration
{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"lib": ["ES2020"],
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"resolveJsonModule": true,
"moduleResolution": "node"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "**/*.test.ts"]
}
// Step 2: Migrate a sample JavaScript file
// Before (index.js):
// module.exports = {
// greet: (name) => `Hello, ${name}!`,
// add: (a, b) => a + b
// };
// After (index.ts):
export function greet(name: string): string {
return
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Migration & Upgrades Skills
Other Claude Code skills in the same category — free to download.
Node Upgrade
Upgrade Node.js version with compatibility fixes
React Upgrade
Upgrade React to latest version
Next.js Migration
Migrate from Pages Router to App Router
Jest to Vitest
Migrate from Jest to Vitest
CJS to ESM
Convert CommonJS to ES Modules
Webpack to Vite
Migrate from Webpack to Vite
Database Migration
Migrate between databases
Want a Migration & Upgrades skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.