What is TypeScript


What is TypeScript

JavaScript is client side language, using it with nodejs has helped JavaScript to emerge has a server-side to. JS does not use Object-oriented programming and hence the codes get messier as it grows big. This is where typescript comes into play.

Typescript which was first launched in 2012. Angular Js 2.0 and 4.0 are built with this platform unlike angular js 1.0 in JavaScript. It is an open source platform built and managed by Microsoft. Typescript is a superset of JavaScript. It is pure object-oriented programming with classes, interface similar to C# or java. Typescript helps you write the code in oop and compile it in JavaScript. Typescript is a language plus some tools, it is just JavaScript with some additional features. Latest stable version is 2.8.3.

Features of Typescript

Typescript starts with JS and ends with JS. The basic building blocks are from JS, hence you only need to know JS to use Typescript. All TypeScript code is converted into its JavaScript equivalent for the purpose of execution.

All JS libraries are supported by Typescript. TypeScript-generated JavaScript can reuse all of the existing JavaScript frameworks, tools, and libraries.

You can convert any valid .js file to .ts by renaming the file and can be compiled with other TypeScript files.

TypeScript is portable across browsers, devices, and operating systems. It can run on any environment that JavaScript runs on.

Benefits of TypeScript

The TypeScript transpiler provides the error-checking feature. TypeScript will compile the code and generate compilation errors, if it finds some sort of syntax errors. This helps to highlight errors before the script is run.

TypeScript supports Object Oriented Programming concepts like classes, interfaces, inheritance, etc.

TypeScript comes with an optional static typin.

Components of TypeScript

Language − It comprises of the syntax, keywords, and type annotations.

Compiler − The TypeScript compiler (tsc) converts the instructions written in TypeScript to its JavaScript equivalent.

Language Service − exposes an additional layer around the core compiler pipeline that are editor-like applications.

Installing TypeScript

There are two ways

  • Via npm (the Node.js package manager)
  • By installing TypeScript’s Visual Studio plugins

Visual Studio 2017 & 2015 Update include TypeScript by default. If you didn’t install TypeScript with Visual Studio, you can still download it.

For NPM users, first install node.js and npm by clicking here. You can install npm using this code

> npm install npm@latest -g

Now using this code install typescript

> npm install -g typescript

After this follow the steps for your first typescript example here.

Also published on Medium.