TypeScript is a superset of JavaScript that adds static typing, interfaces, and type inference on top of JavaScript. But under the hood, it doesn’t run directly — it compiles (transpiles) to plain JavaScript that browsers or Node.js can execute.
Parsing – TypeScript reads your .ts code and converts it into an Abstract Syntax Tree (AST).
Type Checking – The TypeScript compiler (tsc) analyzes the AST and checks that types are consistent.
Transformation – After type checking, TypeScript removes all type information and converts the code into valid JavaScript.
Emission – The transformed JavaScript is written into .js files that can run in any JS environment.
TypeScript input:
function greet(name: string): string {
return `Hello, ${name}!`
}Compiled JavaScript output:
function greet(name) {
return `Hello, ${name}!`
}Notice how type annotations (: string) disappear after compilation — because they’re only used for development-time safety, not runtime execution.
Markdown ASCII Diagram:
┌──────────────────────┐
│ TypeScript Code │
│ (file.ts) │
└──────────┬───────────┘
│
▼
┌──────────────────────┐
│ TypeScript Compiler │
│ (tsc) │
└──────────┬───────────┘
│
┌──────────┴──────────────┐
│ Type Checking (Static) │
└──────────┬──────────────┘
│
▼
┌────────────────────────┐
│ Transpile to JS │
│ (Remove Types) │
└──────────┬──────────────┘
│
▼
┌────────────────────────┐
│ JavaScript Output │
│ (file.js) │
└────────────────────────┘TypeScript improves developer confidence by catching errors before runtime.
It doesn’t slow down execution, since it compiles to pure JavaScript.
TypeScript’s compiler works like a smart assistant, analyzing code before it even runs.
| Stage | Description | Output |
|---|---|---|
| 1 Parsing | Converts .ts code to AST |
Internal structure |
| Type Checking | Validates type rules | Error or continue |
| Transformation | Removes TypeScript-specific syntax | JavaScript AST |
| Emission | Writes .js code |
JavaScript file |