Getting Started With TypeScript – Part 4

Hi Friends,

In this section, we will continue from the last section. Here, we will delve further into types and see the same in action.  Like we have anonymous types in C#, where in compiler can’t figure-out the exact primitive type declared. Similarly, we have in JavaScript, any type as shown below in the example.

Now, if I hover on the same, it will show the type any.

49th

We have already seen in previous post, few primitive types in action. But, let us see again for refresher.

Let us go ahead and look at the same with examples. Below is the TS and equivalent JS snippet. However, there is nothing much difference between these scripts in this case.

As you can see the snippet, here anything can be passed as argument. In this case, I have passed number and below is the result for the same.

50th

I can also pass any string value as well while calling the function.

51th

Now, if I hover on the calling function, It will give very crisp definition for the function as shown below in the screenshot.

52nd

As you can see in the above screenshot, it is saying logMe is a function which is returning nothing, although logging the message in console, taking arg as one argument, which is implicitly getting converted to type any.

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

53rd

I hope you would have liked today’s post. We will delve further around the same in coming posts. Thanks for Joining me.

Thanks,
Rahul Sahay
Happy Coding