Course contentsShow
← TypeScript
Lesson 1699 of 1,79639. TypeScript PerformanceFree lesson

TypeScript's Two-Phase Compilation Model

Understanding how TypeScript separates parsing/binding from type checking for efficient compilation.

TypeScript's Two-Phase Compilation Model

What you'll learn: How TypeScript separates parsing/binding from type checking to compile your code efficiently.

The Two Distinct Phases

When you run tsc, TypeScript doesn't process your code in one monolithic pass. Instead, it separates the work into two distinct phases:

  1. Parsing and Binding Phase: TypeScript reads your source files, builds an Abstract Syntax Tree (AST), and establishes what symbols (variables, functions, types) exist and where they're declared.

  2. Type Checking Phase: Only after the structure is understood does TypeScript validate that types are used correctly—checking assignments, function calls, property access, and all type relationships.

Why This Matters for Performance

Think of it like building a house: first you create the blueprint and lay the foundation (parsing/binding), then you inspect whether everything meets code requirements (type checking). You wouldn't check if the electrical wiring is correct before you even know where the walls are.

This separation enables several performance optimizations:

  • Incremental compilation: TypeScript can skip the type-checking phase for unchanged files
  • Project references: Dependencies can share binding information without re-type-checking
  • Faster editor feedback: Your IDE can parse and bind code instantly while deferring expensive type checks
  • Parallel processing: Different files can be parsed simultaneously

Practical Implications

When you use tsc --noEmit, you're still running both phases—TypeScript must parse and bind before it can type-check. With --incremental, TypeScript saves binding information in .tsbuildinfo files to avoid repeating phase one unnecessarily.

This model is why TypeScript can scale to massive codebases: most edits only require re-checking the type phase for affected files, not rebuilding the entire program structure.

Key Takeaway: TypeScript's two-phase compilation—parsing/binding first, then type checking—enables incremental builds, editor performance, and efficient recompilation by separating "what exists" from "is it used correctly."