Ts 3
Ts 3
// // // Arrays
// // let numbers:number[] = [1,2,3]
// // let names:string[] = ["Manish","Bob","Pranjal"]
// // // enum
// // enum Direction{
// // Up,
// // Down,
// // Left,
// // Right
// // }
// // // interface Person{
// // // name : string;
// // // age : number;
// // // isNepali : boolean
// // // }
// // // let user:Person = {
// // // name : "Manish Basnet",
// // // age : 22,
// // // isNepali : true
// // // }
// // // role : string;
// // // }
// // // let employee:Employee ={
// // // age : 22,
// // // name : "Manish Basnet",
// // // isNepali : true,
// // // role : "Developer"
// // // }
// // // type ID = number
// // // let userId:ID = 99
// // //union
// // type ID = number | string | boolean
// // //intersection
// // type Employee = {
// // name : string;
// // role : string
// // }
// // type Skill = {
// // language : string
// // }
// // let developer:SoftwareEngineer = {
// // name : "Manish",
// // role : "Frontend Dev",
// // language : "Javascript"
// // }
// // function add(a:number,b:number):number{
// // return a + b
// // }
// // interface User{
// // id : number,
// // name : string,
// // email? : string
// // }
// // let friend1:User = {
// // id : 1,
// // name : "Aashish",
// // email : "[email protected]"
// // }
// // Generics in Typescript
// // function addTwoNumber(num1:number,num2:number):number{
// // return num1+num2
// // }
// // function addTwoString(str1:string,str2:string):string{
// // return str1+str2
// // }
// // function add<T>(data1:T,data2:T):string{
// // return `${data1} + ${data2}`
// // }
// function identity<T>(param:T):T{
// return param
// }
// interface Data<T,U>{
// first: T,
// second : U
// }
// let data:Data<number,string> = {
// first : 1,
// second : "Manish"
// }
// let data2:Data<string,number> = {
// first:"Manish",
// second : 1
// }
// class Developer{
// name : string
// position : string
// constructor(name:string,position:string){
// this.name = name
// this.position = position
// }
// code():void{
// console.log("I am coding")
// }
// }
// manish.code()
// Inheritance
// class Animal{
// name : string
// sound : string
// constructor(name:string,sound:string){
// console.log("This is inside Animal cons",name)
// this.name = name
// this.sound = sound
// }
// makeSound():void{
// console.log(`${this.name} says ${this.sound}`)
// }
// }
// constructor(name:string,sound:string,canFly:boolean){
// super(name,sound)
// this.canFly = canFly
// }
// fly():void{
// if(this.canFly){
// console.log(`${this.name} is flying`)
// }else{
// console.log(`${this.name} cannot fly`)
// }
// }
// }
// ostrich.fly()
// class Shape{
// color : string
// constructor(color:string){
// this.color = color
// }
// displayColor():void{
// console.log(`Color: ${this.color}`)
// }
// }
// constructor(radius:number,color:string){
// super(color)
// this.radius = radius
// }
// calculateArea():number{
// return Math.PI * this.radius ** 2
// }
// }
// class Rectangle extends Shape{
// width:number
// height : number
// constructor(width:number,height:number,color:string){
// super(color)
// this.width = width
// this.height = height
// }
// calculateArea():number{
// return this.width * this.height
// }
// }
// class Cat{
// makeSound():void{
// console.log("Meow")
// }
// }
// class Dog{
// makeSound():void{
// console.log("Woof")
// }
// }
// function petSounds(pet:any):void{
// pet.makeSound()
// }
// petSounds(myCat)
// petSounds(myDog)
class Person{
private _name:string
constructor(name:string){
this._name = name
}
getName():string{
return this._name
}
setName(newName:string):void{
if(newName='')
this._name = newName
}
class Shape{
private _color:string
constructor(color:string){
this._color = color
}
displayInfo():void{
const perimeter = this._calculatePerimeter()
console.log(`Perimeter: ${perimeter}`)
}
}