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.
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:- https://github.com/rahulsahay19/TypeScript-Demo
1,961 total views, 1 views today