I am attempting to create an empty object without specifying initial values.
Here is my interface:
interface MyDate {
day: string;
month: string;
year: string;
}
This is my class:
export class MyClass implements OnInit {
date: MyDate = {}; // Error Type '{}' is missing the following properties ...
buildDate([day, month, year]: Array<string>) {
this.date = { day, month, year };
}
}
To address this issue, I could make the keys optional in my interface:
interface MyDate {
day?: number;
month?: number;
year?: number;
}
Another option is to initialize my object like this:
date: MyDate = {
day: '';
month: '';
year: '';
};
However, I prefer to start with an empty object for aesthetic purposes :)