TypeScriptDevelopmentTipsCode Quality

Find TypeScript Errors Across Your Entire Codebase in Seconds

Learn how to quickly check for TypeScript errors across your entire project without compiling, perfect for catching issues before they hit production.

3 min read

TL;DR - Check TypeScript errors
Run this in your terminal:

tsc --noEmit

The Problem

When working on large TypeScript projects, it's easy to:

  • Make breaking changes that affect multiple files
  • Miss type errors in files you haven't opened
  • Push code with hidden type issues
  • Break interfaces used across the codebase

The Solution

The TypeScript compiler's --noEmit flag lets you type-check your entire project without generating JavaScript files. It's like having a full codebase lint in seconds.

Add it to your package.json:

{
  "scripts": {
    "check": "tsc --noEmit"
  }
}

When to Use This

Run this command when you:

  • Refactor shared types or interfaces
  • Update dependencies that might affect types
  • Want to verify your entire codebase is type-safe
  • Before committing major changes
  • After pulling updates from your team

Real-World Example

Let's say you modify a shared interface:

// Before
interface User {
  id: number;
  name: string;
}
 
// After
interface User {
  id: number;
  name: string;
  email: string; // Added new required field
}

Running tsc --noEmit will instantly show all places where the User interface is used without providing an email field:

error TS2741: Property 'email' is missing in type '{ id: number; name: string; }'

Pro Tips

  1. Add it to Your Git Hooks:

    {
      "husky": {
        "hooks": {
          "pre-commit": "tsc --noEmit"
        }
      }
    }
  2. CI Integration:

    - name: Type Check
      run: npm run check
  3. VS Code Integration: Add to .vscode/tasks.json:

    {
      "tasks": [
        {
          "type": "npm",
          "script": "check",
          "problemMatcher": ["$tsc"],
          "group": "test"
        }
      ]
    }

Benefits

  1. Speed: Checks entire codebase in seconds
  2. No Build Required: --noEmit skips JavaScript generation
  3. Comprehensive: Finds errors even in unopened files
  4. Early Detection: Catch issues before they reach production
  5. Team Friendly: Ensure type safety across the team

Common Use Cases

  1. Before Major Refactoring:

    npm run check # Verify current state
    # Make changes
    npm run check # Verify nothing broke
  2. Continuous Integration:

    npm run check || exit 1
  3. With Watch Mode:

    {
      "scripts": {
        "check:watch": "tsc --noEmit --watch"
      }
    }

Note: Make sure your tsconfig.json is properly configured for your project's needs. The effectiveness of this check depends on your TypeScript configuration.

Keep Learning

Get my latest methods and insights delivered to your inbox.

No spam, ever. Unsubscribe anytime.