Getting Started with TypeScript – Part 7

Hi Friends,

In this section, we are going to look creation and implementation of classes in TypeScript. TypeScript provides built in support for class. I have already discussed in the last post, if you are coming from the background C# or Java, then you must be familiar with class. Basically, a class is container whose role is to contain code means making a reusable stuff, such that same can be used time and again.

Now, a class can contain anything like

Functions

Fields

Properties

Constructors etc…

Below, is the simple class snippet with constructor in it.

And, below is the equivalent JS file for the same.

Let me improvise this script and let’s build an Employee Manager relationship class. Below is the snippet for the same.

And equivalent JS for the same.

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

62nd

You may also notice that at each stage, intellisense is helping like shown below.

63rd

Thanks for Joining me. I hope you would have liked today’s discussion. We’ll get back to you with more examples. Till then stay tuned and Happy Coding.

Thanks,
Rahul Sahay
Happy Coding

1,478 total views, 2 views today