TL;DR - Check TypeScript errors
Run this in your terminal:
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
:
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:
Running tsc --noEmit
will instantly show all places where the User
interface is used without providing an email field:
Pro Tips
-
Add it to Your Git Hooks:
-
CI Integration:
-
VS Code Integration: Add to
.vscode/tasks.json
:
Benefits
- Speed: Checks entire codebase in seconds
- No Build Required:
--noEmit
skips JavaScript generation - Comprehensive: Finds errors even in unopened files
- Early Detection: Catch issues before they reach production
- Team Friendly: Ensure type safety across the team
Common Use Cases
-
Before Major Refactoring:
-
Continuous Integration:
-
With Watch Mode:
Note: Make sure your tsconfig.json
is properly configured for your project's needs. The effectiveness of this check depends on your TypeScript configuration.