0Pricing
TypeScript Academy · Lesson

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 repeat

Choosing 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 first

All lessons in this course

  1. Starting the Migration: allowJs and checkJs
  2. JSDoc Type Annotations as a Bridge
  3. File-by-File Conversion Strategy
  4. Dealing with Untyped Third-Party Libraries
← Back to TypeScript Academy