Superset of JS
Compiled to JS by tsc
Works on any OS, browser, host
It's open source
Maintaining big JS projects
Large scale JS Application Architechure
Classes, Inheritance, Interfaces
npm install -g typescript
create helloworld.ts
tsc helloworld.ts
your js file associated with ts is generated
and see an example
var name = 'Lambert'; name = 10 //possible in JS var name = 'Sijin'; name = 1100 //cannot convert string to number
var name:string; var age:number; var cars:Array<string> = [] cars[0] = 'toyota' cars[1] = 9712 // error
function setName(name:string, age:number){ console.log('Age of ' + ' is '+age) } setName('Akhil', 15) setName('Sreenadh', 18) function getName():string{ retrun name; }
there are several ways of decleration
Lets explore it as we dive through it
var getName = ():string =>{ return 'Aboobacker'; }
Objects we have saw on ES6
Lets see in whats in TS
How can we pass an object as an argument.
interface IPerson{ firstName : string; lastName : string; sayHi? : () => void; //? says its function is optional }; function recivePerson(person:IPerson){ person.sayHi(); }
Create an object in TS
class Person{ firstName:string; lastName:string; constructor(fName:string, lName: string){ this.firstName = fName; this.lastName = lName; } sayHi():string { return "My Name is "+this.firstName+" "+this.lastName; } }
Dont use global vars
Protect js code
your code gets ruined when you try to add 3rd party libs
export class Person{ ... }
function overloading
Inheritance
Modules
Decorators
blah blah blah...