0% found this document useful (0 votes)
16 views6 pages

Ts 3

ts

Uploaded by

sachinkunwar284
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views6 pages

Ts 3

ts

Uploaded by

sachinkunwar284
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

// // let num:number = 5

// // let message:string = "Hello world"


// // let isNepali = true

// // // Arrays
// // let numbers:number[] = [1,2,3]
// // let names:string[] = ["Manish","Bob","Pranjal"]

// // // enum
// // enum Direction{
// // Up,
// // Down,
// // Left,
// // Right
// // }

// // let userDirection:Direction = Direction.Up

// // // interface Person{
// // // name : string;
// // // age : number;
// // // isNepali : boolean
// // // }

// // // let user:Person = {
// // // name : "Manish Basnet",
// // // age : 22,
// // // isNepali : true
// // // }

// // // interface Employee extends Person{

// // // role : string;
// // // }

// // // let employee:Employee ={
// // // age : 22,
// // // name : "Manish Basnet",
// // // isNepali : true,
// // // role : "Developer"
// // // }

// // // type ID = number
// // // let userId:ID = 99

// // // type UserName = string


// // // let username:UserName = "Manish Basnet"

// // // let username2:UserName = "Mahesh Basnet"

// // //union
// // type ID = number | string | boolean

// // let userId:ID = 999


// // let userId2:ID = "Manish"

// // //intersection
// // type Employee = {
// // name : string;
// // role : string
// // }

// // type Skill = {
// // language : string
// // }

// // type SoftwareEngineer = Employee & Skill

// // let developer:SoftwareEngineer = {
// // name : "Manish",
// // role : "Frontend Dev",
// // language : "Javascript"
// // }

// // function add(a:number,b:number):number{
// // return a + b
// // }

// // // let result = add(1,2)

// // type Multiply = (a:number,b:number) => number


// // const multiply:Multiply= (a,b)=> a * b

// // let result2 = multiply(1,2)

// // 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}`
// // }

// // let result = add<string>('1','2')

// function identity<T>(param:T):T{
// return param
// }

// let result = identity<number>(10)


// console.log(result)

// 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
// }

// function combine<T extends string | number>(a:T,b:T):string{


// return `${a}${b}`
// }

// let result2 = combine('Manish','Basnet')


// console.log(result2)

// class Developer{
// name : string
// position : string

// constructor(name:string,position:string){
// this.name = name
// this.position = position
// }

// code():void{
// console.log("I am coding")
// }
// }

// let manish = new Developer('Manish','Frontend Dev')


// let pranjal = new Developer('Pranjal','Backend Dev')

// 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}`)
// }
// }

// class Bird extends Animal{


// canFly:boolean

// 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`)
// }
// }
// }

// const eagle = new Bird('Eagle','Screech',true)


// const ostrich = new Bird('Ostrich','Scream',false)
// eagle.makeSound()
// eagle.fly()

// ostrich.fly()

// class Shape{
// color : string

// constructor(color:string){
// this.color = color
// }
// displayColor():void{
// console.log(`Color: ${this.color}`)
// }

// }

// class Circle extends Shape{


// radius : number

// 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
// }
// }

// const blueCircle = new Circle(5,'blue')


// blueCircle.displayColor()
// console.log(blueCircle.calculateArea())

// const redRectangle = new Rectangle(2,5,'red')


// redRectangle.displayColor()

// class Cat{
// makeSound():void{
// console.log("Meow")
// }
// }

// class Dog{
// makeSound():void{
// console.log("Woof")
// }
// }

// function petSounds(pet:any):void{
// pet.makeSound()
// }

// const myCat = new Cat()


// const myDog = new Dog()

// 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
}

// const person = new Person('Manish')


// person._name = "hello"
// console.log(person.setName('Hello'))
// console.log(person.getName())

class Shape{
private _color:string
constructor(color:string){
this._color = color
}

// abstracting the implemetation details


private _calculatePerimeter():number{
console.log("Calculating Perimeter")
return 0;
}

displayInfo():void{
const perimeter = this._calculatePerimeter()
console.log(`Perimeter: ${perimeter}`)
}
}

const myShape = new Shape('red')


myShape.displayInfo()

You might also like