Getting Started with TypeScript – Part 3

Hi Friends,

In this section, we will continue from the last place and explore more into TypeScript. Here, we will be starting with basics of TypeScript, means very much around the syntax areas. Let us look at few samples around the same.

Now, if I hover on the x variable, it will show of type number as shown below.


Now, similar thing can be achieved by using annotation as shown below in the snippet. Here, we are explicitly making the stuff as number.


Now, with annotations, we can force static type checking. Let’s see the below example for instance.

However, while calling the Add function here, intellisense prompts me at every stage as shown below.It says you need to pass two input parameters of type number.


However, when I build the same, it will produce the following error.


Therefore, this is the magic of using TypeScript on top of JavaScript.This way we are actually writing very type safe and robust code. Now, let me fix the same and produce the output.

With the above change in place, it will produce the following output.


I hope you would have liked this discussion. In coming section, we will delve further into TypeScript. Till then stay tuned and Happy Coding.

Download Code Link:-

Rahul Sahay
Happy Coding