You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// number// boolean// any = when no any type is passed like let a; this can have anything
Function
Function argumests should have the typechecking
functionadd(name: string,email: string,isPaid: boolean=false){wearemakingtheispaiddeafultfalsesoitdoesntmakeproblemlaterinthefile}functionreturn(num:number):number{return"hello"// This saids return only number string is now allowded}functionhandeleError(errmsg: string):void{return"hello"//this is the err cause void means return nothing// never in place of the void return but doesnt matter}
Objects
// Function returning Objectsfunctioncreate():{name:string,price:number}{}
Type Alaises
typeUser={name:string,email:string,isActive:boolean}
type Mysting:string// Making the own data typefunctioncreateuser(user:User):User{return{name:"hero",email:"email@gamil",isActive:true}}createuser({name:"khatri",email:"[email protected]",isActive:true})typenew={readonly_id:string//nobody can change thisname:string}letperson:new={_id:"dfasdfa",name:"This is the name"gender?:boolean// question mark here mean that we can put or leave empty too}person.name="this is new name"person._id="dfadf"// this is not avilavle
typeCardNumber={cardNumber:string}typecardData={cardData:string}// It is combining and when we are dong cardDetials we should have the cardnumber and cardDatatypecardDetails=cardNumber&cardDate&{dvv:string}
Arrays
constsuperHeros:string[]=[]// This is telling we have the array of stringsconstsuperHeros:number[][]=[]// Array under array should be the numberconstsuperHeros:costumDatatypes[]=[]// This is telling we have costum typeconstsuperHeros:Array<number>=[]// This is telling we have the array of number
Union in Typescript May be this value or this like num or string
letvalue:number|string=33//number or stringletdata:(number|string)[]=[1,2,"hello"]letseathave:"window"|"Front"|"back"// only can have jsut these theree values