Course contentsShow
← TypeScript
Lesson 897 of 1,79620. The any Escape HatchFree lesson

@ts-nocheck for Entire Files

Disabling type checking for an entire file during migration or for legacy code using @ts-nocheck at the top.

@ts-nocheck for Entire Files

What you'll learn: How to disable TypeScript's type checker for an entire file when migrating legacy code or dealing with temporary type issues.


What Is @ts-nocheck?

@ts-nocheck is a special comment directive you place at the very top of a TypeScript file to completely turn off type checking for that entire file. It's the nuclear option—TypeScript will treat the file as if it were plain JavaScript, ignoring all type errors.

Think of it like putting a "Do Not Disturb" sign on a hotel room door. TypeScript sees the sign and walks right past without inspecting anything inside.

The Syntax

// @ts-nocheck

// Everything below this line is not type-checked
let x: number = "this is fine"; // No error!
const result = unknownFunction(); // No error!

The comment must appear at the very top of the file, before any code or other comments.

When to Use @ts-nocheck

This directive is most useful in two scenarios:

1. During Migration: When converting a large JavaScript codebase to TypeScript, you might add .ts extensions to files gradually. Use @ts-nocheck to silence errors in files you haven't migrated yet while still benefiting from TypeScript elsewhere.

2. Legacy or Generated Code: Files that are auto-generated, extremely complex, or use patterns TypeScript struggles with can be temporarily excluded while you focus on more critical code.

How It Differs from @ts-ignore

  • @ts-ignore (previous lesson): Suppresses the next line only
  • @ts-nocheck: Suppresses the entire file

Use @ts-nocheck when a file has dozens of errors and you need a clean slate. Use @ts-ignore for targeted, line-by-line suppression.

Important Warnings

This directive should be temporary. A file with @ts-nocheck gives you zero type safety—the same as plain JavaScript. Your goal should be to remove it eventually by fixing the underlying issues.

Key Takeaway: @ts-nocheck at the top of a file completely disables type checking for that file, making it useful during migration but dangerous if left permanently.