File-by-File Conversion Strategy
Rename .js to .ts incrementally without breaking anything.
The Incremental Approach
File-by-file conversion renames one .js to .ts at a time, fixing type errors as you go. This keeps the project compiling at every step.
# Step 1: rename
mv src/utils.js src/utils.ts
# Step 2: fix errors
npx tsc --noEmit
# Step 3: commit and repeatChoosing Where to Start
Start with leaf modules — files with no imports from other project files. These have no downstream TypeScript dependencies to satisfy first.
# Find files with fewest imports from other project files:
grep -r "from './" src --include="*.js" | sort | uniq -c | sort -n
# Convert lowest-count files firstAll lessons in this course
- Starting the Migration: allowJs and checkJs
- JSDoc Type Annotations as a Bridge
- File-by-File Conversion Strategy
- Dealing with Untyped Third-Party Libraries