I'm facing an issue with my address interface setup. Here is how it's defined:
export interface Address {
addressType: {
house?: {
streetAddress: string,
city: string,
zip: string,
},
apartment?: {
streetAddress: "",
unitNumber: "",
city: "",
zip: "",
buildingName?: "",
},
}
instructions?: string;
}
In my Typescript component file, I have tried to define a house address like this:
address: Address;
constructor() {
this.address.addressType = {
house: {
streetAddress: "1 test",
city: "test city",
zip: "92222",
}
}
console.log(this.address);
}
However, when I log the address to the console, I encounter the error message:
Uncaught (in promise): TypeError: Cannot set property 'addressType' of undefined
I believed I was setting the addressType correctly in the constructor. Is there a more effective way to achieve what I intend to do?