TypeScript (TS) is a strongly typed programming language built on top of JavaScript. It is developed and maintained by Microsoft.
In simple words:
TypeScript = JavaScript + Static Type Checking
It helps developers catch errors before running their applications.
1. Why do we need TypeScript?
Consider this JavaScript code:
let amount = 1000;
amount = "Hello";
console.log(amount);
JavaScript allows this because it is dynamically typed.
Now look at TypeScript:
let amount: number = 1000;
amount = "Hello"; // Error
Typescript support, interfaces, generics, Type aliases.
3. How does TypeScript work?
TypeScript code cannot run directly in browsers or Node.js as TypeScript.
It is first converted into JavaScript.
TypeScript does not replace JavaScript.
It adds a type system on top of JavaScript.