typescript model code example
Example 1: create model in typescript
type DonutChartModel = {
dimension: number;
innerRadius: number;
};
var donut: DonutChartModel = {
dimension: 1,
innerRadius: 2
};
Example 2: class inheritance in typescript
class Info {
protected name: string ;
constructor(n:string){
this.name = n ;
};
describe(){
console.log(`Your name is ${this.name}`);
}
}
class Detail extends Info{
constructor(name:string, public age:number){
super(name);
}
findAge(){
console.log(`${this.name} age is ${this.age}`)
}
}
const b = new Detail('jank', 23);
b.describe();
b.findAge();
Example 3: ts create nex field
var obj:any = {}
obj.prop = 5;