What tsc Does: Type-Checking and Transpilation
You'll learn: The two fundamental jobs the TypeScript compiler performs and how they work together.
The Dual Role of tsc
When you run tsc, the TypeScript compiler does two separate jobs in one pass:
- Type-checking — analyzing your code for type errors
- Transpilation — converting TypeScript into JavaScript
Think of tsc like an editor who both proofreads your manuscript for errors AND translates it into another language. These are distinct tasks happening together.
Type-Checking: The Safety Pass
First, tsc analyzes your TypeScript code against its type system. It checks:
- Are you passing the right types to functions?
- Do your variables match their declared types?
- Are you accessing properties that exist?
- Do your return types match what you promised?
This happens entirely at compile-time. If errors are found, tsc reports them to you. Importantly, type information doesn't appear in the final JavaScript — it's only for catching mistakes before runtime.
Transpilation: The Transformation Pass
After (or alongside) type-checking, tsc strips away all the TypeScript-specific syntax and generates plain JavaScript. This involves:
- Removing type annotations
- Converting TypeScript-only features to JavaScript equivalents
- Transforming newer syntax to older versions (based on your
targetsetting) - Generating source maps if requested
The output is standard JavaScript that browsers and Node.js can run.
Why Both Matter
These two jobs are independent: you can type-check without emitting files (--noEmit), or emit files even when errors exist (by default). This separation gives you flexibility in your build pipeline — maybe you want to check types separately from bundling, or continue building even with type warnings.
Key Takeaway: tsc performs both static type analysis (catching errors) and code transformation (producing JavaScript), making TypeScript both a type checker and a transpiler in one tool.