How TypeScript Compilation Works? Last Updated : 18 Mar, 2025 Comments Improve Suggest changes Like Article Like Report TypeScript is a superset of JavaScript that adds type safety to your code. It compiles into plain JavaScript, allowing it to run in any JavaScript environment.The TypeScript compiler (tsc) checks the code for errors and then converts it into JavaScript. During this process, all TypeScript-specific features like type annotations are removed, leaving behind clean JavaScript code.Let's understand how TypeScript compilation works: Steps of TypeScript CompilationThe TypeScript compilation process transforms your TypeScript code into executable JavaScript. Here’s how it works step by step:Parsing: The TypeScript compiler parses the code to create an Abstract Syntax Tree (AST). This tree represents the structure of your code in a way that the compiler can understand and manipulate.Type-Checking: The compiler examines the code to determine the types of variables, functions, and expressions. This step ensures type safety by catching type-related errors before the code is executed.Generating JavaScript: After type-checking, the compiler produces JavaScript code. During this phase, type annotations are removed, and TypeScript-specific features are converted into JavaScript equivalents.Bundling (Optional): To optimize performance, the generated JavaScript code can be bundled using tools like Webpack or Rollup. Bundling reduces the number of HTTP requests by combining multiple files into one.Execution: The final JavaScript code is executed in a browser or server environment.ExampleHere we are going to see a TypeScript code snippet and its corresponding compiled JavaScript output. This will help you understand how TypeScript's type annotations and features are translated into standard JavaScript.TypeScript Code: JavaScript let displayData = ( id: number, name: string, field: string) : string => { return (id + " - " + name + " - " + field); } console.log(displayData(1 , "Aman", "CSE")); In this Typescript Code we are defined Function Invocation: displayData(1, "Aman", "CSE") is called, and the result is logged to the console.Compiled JavaScript Code:After compiling the TypeScript code, the resulting JavaScript code is: JavaScript var displayData = function (id, name, field) { return id + " - " + name + " - " + field; }; console.log(displayData(1, "Aman", "CSE")); Function Definition: The arrow function is converted to a regular function expression.Type Annotations: Type annotations are removed, as JavaScript doesn't support them.Output: 1 - Aman - CSEBasic Facts About TypeScriptHere are some basic facts about TypeScript:Superset of JavaScript: TypeScript is built on top of JavaScript. It adds static typing and other features, but any valid JavaScript code is also valid TypeScript code.Compilation to JavaScript: Browsers and Node.js can’t run TypeScript directly. It must be compiled (transpiled) into plain JavaScript before execution.Developer Tool: TypeScript helps catch errors early during development and improves code documentation with types, making it easier to maintain and understand.TypeScript Compilation FlawsWhile TypeScript offers significant advantages, it's important to be aware of its limitations, particularly concerning compilation:No Runtime Checks: TypeScript checks for errors only during compilation. Once it’s converted to JavaScript, those checks are gone. Runtime errors can still occur.Debugging Challenges: Errors in the compiled JavaScript might not directly match your original TypeScript code, making debugging trickier.Strictness: The strict type system can feel overly restrictive at times, requiring extra effort to satisfy the compiler even when your logic is correct. Comment More infoAdvertise with us Next Article How TypeScript Compilation Works? amansingla Follow Improve Article Tags : JavaScript Web Technologies TypeScript JavaScript-Questions Similar Reads How to compile a Typescript file ? TypeScript is a robust, open-source programming language developed and maintained by Microsoft. As a syntactic superset of JavaScript, TypeScript enhances its foundational language by introducing additional features, including strong typing and object-oriented programming capabilities. Unlike JavaSc 3 min read Hello World in TypeScript TypeScript is an open-source programming language. It is developed and maintained by Microsoft. TypeScript follows javascript syntactically but adds more features to it. It is a superset of javascript. The diagram below depicts the relationship:Typescript is purely object-oriented with features like 3 min read How JavaScript Works? JavaScript is a dynamically typed, cross-platform threaded scripting and programming language, used to put functionality and interactivity at the client side as well as to write logic on the server side of a website. It can display content updates, interactive maps, control multimedia, interactive f 13 min read Introduction to TypeScript TypeScript is a syntactic superset of JavaScript that adds optional static typing, making it easier to write and maintain large-scale applications.Allows developers to catch errors during development rather than at runtime, improving code reliability.Enhances code readability and maintainability wit 5 min read How does JavaScript Hoisting work internally ? In simple terms, hoisting in JavaScript refers to the fact that variables can be used before they're declared. The declared variables are somehow virtually moved to the top of the scope. However, hoisting applies only to variable declarations and not to variable initialization. While almost anyone 4 min read TypeScript Ambients Declaration The Ambient declarations in Typescript are used to tell the typescript compiler that the actual code exists somewhere else. The third-party library that is written in plain JavaScript or CoffeeScript like jquery/angularjs/nodejs, while this is needed for our TypeScript use, then we can always write 2 min read TypeScript Cheat Sheet TypeScript is a strongly typed, object-oriented, compiled programming language developed and maintained by Microsoft. It is a superset of JavaScript, adding static types and other powerful features to improve development efficiency and code quality. TypeScript is widely used in web development, espe 6 min read Is JavaScript Interpreted or Compiled ? JavaScript is an interpreted language. To understand this better, let's look at interpreters, compilers, and JIT (Just-In-Time) compilers: 1. Interpreter: An interpreter runs instructions directly from the programming language without changing them into machine code first. 2. Compiler: A compiler ch 2 min read What is TypeScript Map file ? Before getting ahead, these are few terms you should be familiar with: TypeScript Source files: These are files written by yourself and are quite easy to Interpret, i.e., it is Human-Readable. Emitted or Transpiled JavaScript Code: This code is equivalent JavaScript code of the TypeScript source fil 3 min read How V8 compiles JavaScript code ? V8 is a high-performance, open-source JavaScript and WebAssembly engine used by Google Chrome and Node.js. In this article, we will be going to see what happens behind the scene of V8 Architecture. There are basically three steps involved in processing the code: Parsing the codeCompiling the codeExe 6 min read Like