by Touhidur Zaman, Web Instructor, Job Placement Team, Programming Hero.

Introduction to TypeScript

What is TypeScript?

TypeScript is a powerful, open-source programming language that is built on JavaScript by adding optional static typing. In simple words, TypeScript is a syntactic superset of JavaScript.

TypeScript helps developers to specify the types of variables, function arguments, and return values, where types are determined at runtime (development environment). TypeScript checks for type-related errors while you're writing the code at runtime, reducing the chances of bugs. TypeScript is compiled into JavaScript, making it compatible with all JavaScript environments.

TypeScript vs JavaScript

Feature TypeScript JavaScript
Typing Provides static typing Dynamically typed
Tooling Comes with IDEs and code editors Limited built-in tooling
Syntax Similar to JavaScript, with additional features Standard JavaScript syntax
Compatibility Backward compatible with JavaScript Cannot run TypeScript in JavaScript files
Debugging Stronger typing can help identify errors May require more debugging and testing

image.png

TypeScript Compilation

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.

TypeScript (.ts)
        ↓
TypeScript Compiler (tsc)
        ↓
JavaScript (.js)
        ↓
Browser / Node.js

Steps of TypeScript Compilation

The TypeScript compilation process transforms your TypeScript code into executable JavaScript. Here’s how it works step by step: