create typescript object code example
Example 1: define object properties typescript
interface ISomeObject {
subPropertie1: string,
subPropertie2: number,
}
interface IProperties {
property1: string,
property2: boolean,
property3: number[],
property4: ISomeObject,
property5: ISomeObject[],
}
function (args:IProperties): void { // Sample Usage
console.log(args.property1);
}
Example 2: class inheritance in typescript
// Parent class
class Info {
protected name: string ;
constructor(n:string){
this.name = n ;
};
describe(){
console.log(`Your name is ${this.name}`);
}
}
//inherited class (you can overwrite methods of parent class, super is used to
// connect to the parent parameter(s) . )
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();