// Basic Types and Type AnnotationsletisDone:boolean=false;letdecimal:number=6;letcolor:string="blue";letlist:number[]=[1,2,3];lettuple:[string,number]=["hello",10];// EnumenumDirection{Up="UP",Down="DOWN",Left="LEFT",Right="RIGHT"}// InterfaceinterfaceUser{readonlyid:number;name:string;age?:number;// Optional property[key:string]:any;// Index signature}// Generic InterfaceinterfaceResponse<T>{data:T;status:number;}// Class with implements and extendsabstractclassAnimal{protectedname:string;constructor(name:string){this.name=name;}abstractmakeSound():void;}// Interface for class implementationinterfacePet{play():void;}classDogextendsAnimalimplementsPet{privatebreed:string;constructor(name:string,breed:string){super(name);this.breed=breed;}makeSound():void{console.log("Woof!");}play():void{console.log(`${this.name} is playing!`);}}// Union TypestypeStringOrNumber=string|number;letflexible:StringOrNumber="hello";flexible=42;// Intersection TypestypeEmployee=User&{employeeId:number};// Utility TypestypeReadonly<T>={readonly[PinkeyofT]:T[P];}// Type GuardsfunctionisString(value:any):valueisstring{returntypeofvalue==="string";}// Genericsfunctionidentity<T>(arg:T):T{returnarg;}// Generic ConstraintsinterfaceLengthwise{length:number;}functionloggingIdentity<TextendsLengthwise>(arg:T):T{console.log(arg.length);returnarg;}// Mapped TypestypeOptional<T>={[PinkeyofT]?:T[P];}// Conditional TypestypeNonNullable<T>=Textendsnull|undefined?never:T;// Template Literal TypestypeEventName=`on${string}`;typeSize='small'|'medium'|'large';typeColor='red'|'blue'|'green';typeStyleVariant=`${Size}-${Color}`;// Decoratorsfunctionlog(target:any,propertyKey:string){console.log(`${propertyKey} accessed`);}// Async/Await with TypeScriptasyncfunctionfetchData<T>(url:string):Promise<T>{constresponse=awaitfetch(url);returnresponse.json();}// Type AssertionsletsomeValue:unknown="this is a string";letstrLength:number=(someValueasstring).length;// Literal TypestypeDiceRoll=1|2|3|4|5|6;letdiceResult:DiceRoll=1;// Function Overloadsfunctionprocess(x:number):number;functionprocess(x:string):string;functionprocess(x:number|string):number|string{returnx;}// NamespacenamespaceValidation{exportinterfaceStringValidator{isValid(s:string):boolean;}}// Example Usageconstuser:User={id:1,name:"John",customField:"value"};constdog=newDog("Rex","Golden Retriever");constnumberIdentity=identity<number>(42);constresponse:Response<string>={data:"Success",status:200};// Type InferenceletinferredArray=[1,2,3];// Type is number[]letinferredObject={x:10,y:20};// Type is { x: number, y: number }// Readonly ArraysconstreadonlyNumbers:ReadonlyArray<number>=[1,2,3];// Index TypesfunctiongetProperty<T,KextendskeyofT>(obj:T,key:K):T[K]{returnobj[key];}