Getting Started with TypeScript – Part 5

Hi Friends,

This will be the continuation of learning TypeScript from scratch.

As, you can see in the above snippet, here in the object literal, I am having one variable, which is taking care or rectangle calculation, pretty straight forward stuff.

54th

Now, let us go ahead and modify the literal bit more to support square calculation as well.

In the above snippet, I have added one more variable to take care square calculation. Here, I have passed value from the literal itself rather than passing while calling the same. That’s ok, these stuffs don’t matter anymore.

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

55th

However, in order to understand the conversion @TypeScript level, when I hover on calling function, then it will produce the following stuff.

56th Now, let me go ahead and rewrite the same using Arrow function. Arrow function is a short and compact way of writing function as shown below in the snippet.

With the above change in place, when I run the app, it will produce me the following output.

57th

I hope you would have liked this discussion. We will continue the same in coming posts. Till then stay tuned and Happy Coding.

Thanks,
Rahul Sahay,
Happy Coding

1,582 total views, 1 views today