As I delve into the world of Angular and TypeScript, I am faced with a dilemma regarding how to initialize an object before receiving data from an API request.
Take for instance my model:
//order.model.ts
export class Order {
constructor(public id: number, currency: string, public contact: Object, public items: Array<Object>) {}
}
In one of my components, let's say the App component, I attempt to instantiate this model:
//app.component.ts
export class AppComponent {
@Input()
public order: Order = new Order();
}
However, when trying to create a new Order object, it requires 4 arguments but none were provided. Should I pass in undefined or empty values for each attribute of Order?
In React (without TypeScript), I would simply initialize with an empty object:
this.state = {
order: {}
}
What is considered best practice for handling this situation in Angular and TypeScript?