Type Script

 is a additiondal feature for java script

typescrip= additional +typescript


/*
ES5-

our current browser cannot understand es6
typescript also cannot understand.
**-typescript convert script to javascript,es5-browser and protractor will understand-.
**-scan the existing intenstiosn , symantics

1- npm install -g typescript
2-create a class bascis.ts
3-tsc basics.ts
4-it will create the js file -basics.js
5-run node basics.js

*/
basics.ts
for(var i =0;i<5;i++){setTimeout(function(){console.log(i);},100*i);
}


basics.js
for (var i = 0; i < 5; i++) {
setTimeout(function () { console.log(i); }, 100 * i);
}

Export --

export class classDemo
{

// variable is called in class as property
//Class consists of properties,methods,constructor
//This - refere to current class property

username:string;
password:string;
ssn:number;

//default constructor
constructor(ssn:number){
this.ssn=ssn;
}

//Parameterized constructor

getSsn(){
console.log(this.ssn);
}
getUsername(){
console.log(this.username);
}

setUsername(uName){
this.username=uName;

}
}
// create object of the class, using object call the methods and propertiesof that class
let ocd= new classDemo(1234);
ocd.setUsername('sudheer');
ocd.getUsername();
ocd.getSsn();





import { classDemo } from "./classDemo";


let acc = new classDemo(7777);
acc.getSsn();


******result
bindureddy@sudheerchittireddy Typescript % tsc Access.ts bindureddy@sudheerchittireddy Typescript % node Access.js sudheer 1234 7777

Comments

Popular posts from this blog

Implicit and Explicit Waits,FluentWait,PageLoadTimeOut

A Interview Questions- selenium