TypeScript Academy · Lesson

Starting the Migration: allowJs and checkJs

Enable TypeScript checking in a JavaScript project.

Lesson 1 of 413 steps

Starting the Migration: allowJs and checkJs is a free TypeScript Academy lesson on CoddyKit. This is lesson 1 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, and your progress syncs across the web and the CoddyKit app. The TypeScript Academy course includes 4 lessons in total.

The Migration Challenge

Migrating a large JavaScript codebase to TypeScript all at once is risky. The incremental path: enable TypeScript gradually, file by file, while keeping the project functional.

# Key compiler flags for gradual migration:
# allowJs — allow .js files in the compilation
# checkJs — type-check .js files with JSDoc types

Step 1: Install TypeScript

Add TypeScript to the project and create a minimal tsconfig without strict mode initially.

npm install --save-dev typescript
npx tsc --init
# Edit tsconfig.json to set allowJs: true

allowJs: true

With allowJs: true, TypeScript includes .js files in the compilation. Type checking is permissive — most JavaScript will compile without errors.

{
  "compilerOptions": {
    "allowJs": true,
    "outDir": "./dist",
    "target": "ES2020"
  },
  "include": ["src"]
}

checkJs: true

checkJs: true enables type checking for JavaScript files using inferred types and JSDoc annotations. It surfaces obvious bugs without requiring .ts conversion.

{
  "compilerOptions": {
    "allowJs": true,
    "checkJs": true
  }
}

Suppressing Errors with @ts-nocheck

Add // @ts-nocheck at the top of problematic JS files to suppress all TypeScript errors while you work on the migration incrementally.

// @ts-nocheck
// This file is not yet migrated — errors suppressed
function legacyUtil(x) { return x.foo.bar; }

Per-Line Error Suppression

Use // @ts-ignore to suppress a single line error without disabling the entire file.

const result = legacyFn(value); // @ts-ignore
// Only this line's error is suppressed

maxNodeModuleJsDepth

By default TypeScript checks JS files only in your project. Set maxNodeModuleJsDepth to control how deeply it checks JS in node_modules.

{
  "compilerOptions": {
    "maxNodeModuleJsDepth": 1 // Check 1 level deep in node_modules
  }
}

Compiling JS to Dist

With allowJs, the TypeScript compiler can transpile JS files too — useful for applying polyfills and targeting older environments uniformly.

tsc
# Compiles both .ts and .js files to dist/

Measuring Progress

Track migration progress by counting .js vs .ts files. Set a goal for the percentage converted per sprint.

find src -name "*.ts" | wc -l   # TypeScript files
find src -name "*.js" | wc -l   # JavaScript files remaining

Avoiding Type Regression

Keep noImplicitAny: false initially so existing JS files don't flood with errors. Enable it after converting each file to TypeScript.

{
  "compilerOptions": {
    "allowJs": true,
    "noImplicitAny": false // Relax for JS files; enable per .ts file
  }
}

Recap: Starting the Migration

Start migration with allowJs: true and checkJs: true, use @ts-nocheck for unready files, and track progress by file count. This approach keeps the project compiling while you convert files incrementally.

Quick Check

What does checkJs: true do without requiring .js to .ts conversion?

What You Learned

Start the JS→TS migration with allowJs: true and optionally checkJs: true. Use @ts-nocheck to silence unready files, and convert files incrementally while tracking progress by file count.

Free to start

Learn TypeScript with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
101
Lessons
352

Frequently Asked Questions

Is the “Starting the Migration: allowJs and checkJs” lesson free?

Yes — the full text of “Starting the Migration: allowJs and checkJs” is free to read here on the web. 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. The TypeScript Academy course includes 4 lessons in total.

What will I learn in “Starting the Migration: allowJs and checkJs”?

Enable TypeScript checking in a JavaScript project. 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, so you can start here or from the beginning and move at your own pace. This is lesson 1 of 4.

How long does the “Starting the Migration: allowJs and checkJs” 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