Wednesday, May 31, 2017

How to declare the variable in Type Script

Customer.Ts:

class CustomerDetails{
  public CustomerName: string = "";
  public CustomerNumber: int = 0;
}


  • First should define the type of scope "Public / Private / Protected etc....".
  • Next, give the name of the varible.
  • Next, provide the type of variable as "string / int / boolean etc...." but before this we should have ":" to declare the type of variable.

How to create a class in Type Script?

Customer.Ts:

class CustomerDetails{

}

In Type script, for each Type Script (.ts) files it will generate Java Script (.js) file with the same file name.

The above code will render in Customer.js file as below:

var CustomerDetails= (function(){
  *****
  *****
  *****
return CustomerDetails;
}());