Advise of better and correct approach in creating object and using in Type script and angular?

ACHARYA A K
Feb 27, 2023

Here is code

// ********** First Approach 

class MyCarComponent {
private car: object = { };

constructor(){
this.car['name'] = "AudI";
this.car['model'] = "2017";
}
}

// *********** 2nd Approach
class Car {
name: string;
model: string;
}

class MyCarrComponent {
private car: Car = new Car();

constructor(){
this.car.name = "AudI";
this.car.model = "2017";
}
}

Please comment for correct appraoch

--

--