0Pricing
TypeScript Academy · Lesson

File-by-File Conversion Strategy

Rename .js to .ts incrementally without breaking anything.

File-by-File Conversion Strategy is a free TypeScript Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the TypeScript Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

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

Handling Implicit any Errors

When a JS file is renamed to .ts, parameters without types become implicit any errors if noImplicitAny: true. Add explicit types or use any temporarily.

// Before: JS
function process(data) { return data.value; }

// After: TS (add annotation)
function process(data: { value: string }) { return data.value; }
// Or temporarily:
function process(data: any) { return data.value; }

Suppressing Errors Temporarily

Use // @ts-ignore on hard-to-fix lines and track them as TODOs so they are not forgotten.

// TODO: type this properly in follow-up PR
// @ts-ignore
const result = complexLegacyFunction(x);

Updating Import Statements

When a file becomes .ts, its consumers may need updated imports. TypeScript resolves .ts files automatically without file extensions in import paths.

// No extension needed — TypeScript finds .ts
import { process } from "./utils";

Converting Third-Party Requires

Replace CommonJS require calls with ES module import syntax during conversion to match TypeScript module resolution.

// Before: CommonJS
const fs = require("fs");
// After: ES module
import fs from "fs";

Strict Mode Progression

Enable strict flags incrementally per file using per-file // @ts-strict-ignore comments or by migrating to a separate tsconfig with strict on.

// tsconfig.strict.json — points to converted files only
{
  "extends": "./tsconfig.json",
  "compilerOptions": { "strict": true },
  "include": ["src/converted/**/*"]
}

Tracking Remaining Files

Keep a checklist or use a script to count remaining .js files and track migration progress over time.

find src -name "*.js" | wc -l   # remaining JS files
find src -name "*.ts" | wc -l   # converted TS files

Avoiding Large PRs

Convert one file per PR to keep reviews manageable. Large TypeScript migrations are easier to review and revert when scoped to individual files.

# Good: one file per PR
# Bad: 50 files renamed in one PR

Running Tests After Each Conversion

Run the test suite after each file conversion to catch runtime regressions that TypeScript's type checker might not catch.

npm test
# Ensure all tests pass after each .js → .ts rename

Recap: File-by-File Strategy

Convert leaf files first, fix or suppress errors, keep the project compiling at every step, track remaining JS files, and submit one file per PR for manageable reviews.

Quick Check

Which files should you convert to TypeScript first in a file-by-file migration?

What You Learned

File-by-file migration: start with leaf modules, rename to .ts, fix or suppress errors, keep the project compiling, and track progress. Small per-PR conversions make migration safe and reviewable.

Frequently asked questions

Is the “File-by-File Conversion Strategy” lesson free?

Yes — the full text of “File-by-File Conversion Strategy” is free to read here on the web, and the TypeScript Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the TypeScript Academy course, upgrade to CoddyKit PRO.

What will I learn in “File-by-File Conversion Strategy”?

Rename .js to .ts incrementally without breaking anything. You practise TypeScript Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start TypeScript Academy?

No prior experience is required. TypeScript Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “File-by-File Conversion Strategy” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this TypeScript Academy lesson?

Yes. Every TypeScript Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

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