This video will teach you on how to create a class in TypeScript, how to create object, how to create constructor, how to create getters & setters.
Source Code:
class Person{
name:string;
age:number;
public constructor(name:string, age:number){
this.name = name;
this.age = age;
}
public getName():string{
return this.name
}
public setName(name:string){
this.name = name;
}
}
let p1 = new Person("Arun",25);
console.log(p1.getName());
p1.setName("Kumar");
console.log(p1.getName());
Output:
Arun
Kumar