What is TypeScript. Its Installation and Features

Typescript is a superset to JavaScript. It offers more feature than JavaScript like

  • Classes
  • Interface
  • Strong Typing
  • and many more

Vanilla JavaScript has dynamic typing. Typescript does not run in the browser, So it is compiled to JavaScript in the end.

Installation

To install TypeScript locally you first need to install NodeJS in your PC. You can click on https://nodejs.org/en/ link and install NodeJS.

If NodeJS is already install in your pc then copy TypeScript command from below and run copied command in command prompt. Below command is only applicable to you current Project/folder

npm install typescript

If you want to install TypeScript globally then copy below command and execute in command prompt. -g stands for globally

npm install -g typescript

Compilation

Below simple example is add two values. In this example you can see add function contains two number type argument which I define a: number.

You can compile by execute below command

npx tsc add.ts

One more file is created with same name but extension is js that is add.js

If you pass string in add function it will give error in compilation