First of all Why, Why need TypeScript, What the purpose of TypeScript
Ok, let’s create a simple application to display the content of div on browser using TypeScript.
Step 1. Create a new project with visual studio 2015 > File > New > Project
Click ok button, after that you can see below screen.
There is app.ts, its typescript file, extension is ts, and we can write typescript code in ts file. So now we will be creating new ts file.
Step 2. Creating new ts file
Right click on the project > click add > click TypeScript File, you can name it as Hello.ts and click ok button.
Now Hello.ts file has been added to your project.
As you can see in the above image ,I have created Hello class. There are element properties and a constructor which take a parameter, parameter type is HTMLElement. On window load I have create instance of Hello class by that constructor will be called automatically which sets the innerHTML of Div(contentDiv).
Step 3. Create Index Page
Create new Index.html page but, Index.html already existed in this application, so we just add the Hello.ts reference on the Index.html look see the below image.
Step 4. Now Run the browser and get the out put
See here “Hello, Welcome TypeScript” this come from “Hello.ts” typescript file
Ok, now let’s see some basic points of TypeScript
DataType and Enum
Right click on project click add>click TypeScript file name “DataTypeAndEnum.ts” and click ok button.
Check the above image, I have added enum Gender and data types Boolean,number, and string in class DataTypeAndEnum.
Now I am creating function “GetName” without any parameter and return type is string, but we can create parametrize and any return type and non- return type function as a normal programming language.
See the example one is parent class and second is child class, child class inherit the parent class.
Static Functions & Properties
As we know static functions and properties only called by their class reference and cannot be called by an object reference.