Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Here is an architecture of TypeScript — The high-level compilation pipeline diagram, Detailed breakdown of the TypeScript compiler, Parsing and AST generation, Type checking and static analysis, Transformation and removal of type annotations, Emission of JavaScript output, Execution flow and why the architecture matters, A summary comparison table.

Notifications You must be signed in to change notification settings

Lussskki/typescript_under_the_hood

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

TypeScript — Under the Hood

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.

What Happens Under the Hood

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.

Example

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.

TypeScript Compilation Flow

Markdown ASCII Diagram:

          ┌──────────────────────┐
             TypeScript Code    
               (file.ts)        
          └──────────┬───────────┘
                     
                     
          ┌──────────────────────┐
            TypeScript Compiler 
                  (tsc)         
          └──────────┬───────────┘
                     
          ┌──────────┴──────────────┐
            Type Checking (Static) 
          └──────────┬──────────────┘
                     
                     
          ┌────────────────────────┐
             Transpile to JS       
             (Remove Types)        
          └──────────┬──────────────┘
                     
                     
          ┌────────────────────────┐
             JavaScript Output     
               (file.js)           
          └────────────────────────┘

Why This Matters

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.

Markdown-formatted table

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

About

Here is an architecture of TypeScript — The high-level compilation pipeline diagram, Detailed breakdown of the TypeScript compiler, Parsing and AST generation, Type checking and static analysis, Transformation and removal of type annotations, Emission of JavaScript output, Execution flow and why the architecture matters, A summary comparison table.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published