TypeScript is a superset of JavaScript.That means every javascript code is a valid typescript code. But typescript has more features than Javascript like strong typing, object-oriented features, Great tools, and catching errors in compile-time instead of run time. . The typeScript was launched in October 2012 by Microsoft. The first version was Typescript 0.8. The latest version is typescript 4.0.

Typescript superset

Setting up typescript into your workplace.

Open your command prompt and follow the below commands.

npm install -g typescript
mkdir ts-new
cd ts-new
code main.ts
start TS
tsc main.ts
node main.js
node output

Variable declaration

We can use two keywords to declare a variable. I hope to give you a basic idea about the difference between let and var.

1- var

Variables which define using ‘var’ keyword scope to the nearest function.

variable result
let result

Data types

There are few data types in TS. Those are number, string, boolean, any’ likewise. except that we can declare ‘number array’ s and ‘any array’. You can declare variables with the type of each variable.

data types

Type assertions

type assertion

Arrow function

In TS, we can define functions as Arrow functions. At that time, we can drop the function keyword. If you have used C#, you may have seen this type of function. Those are called Lambda functions. Let's see how to define…

arrow function


If we have to pass few parameters to a function, instead of using inline annotation, we can use interface as a most suitable way. This may help to use those parameter values easily in related functions.

inline annotation


Basically, a class means in TS, Group variables(properties), and functions (methods) that are highly related.

without using class


I have included few basics and main points of Typescript in this blog. There are many more things to discuss. My idea was to give you a basic understanding and why we need typescript in web development with javascript. Understanding Typescript will helpful to learn web frameworks as well. I hope to continue this publication with more complex concepts in typescript such as Objects, Constructors, Access Modifiers, and Modules.

Undergraduate in university of Moratuwa, Sri Lanka.