DEV Community

Cover image for Advise of better and correct approach in creating object and using in Type script and angular?
Acharya Anil
Acharya Anil

Posted on

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

// ********** 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";
    }
}
Enter fullscreen mode Exit fullscreen mode

Please comment for correct approach

Top comments (0)