I have an interface defined as:
export interface Address {
addressType: {
house?: {
streetAddress: string,
city: string,
zip: string,
},
apartment?: {
streetAddress: "",
unitNumber: "",
city: "",
zip: "",
buildingName?: "",
},
}
instructions?: string;
}
Then in my Typescript file of my component, I am defining a house address:
address: Address;
constructor() {
this.address.addressType = {
house: {
streetAddress: "1 test",
city: "test city",
zip: "92222",
}
}
console.log(this.address);
}
Though when I log the address to the console, I get:
Uncaught (in promise): TypeError: Cannot set property 'addressType' of undefined
I thought I was setting the addressType in the constructor. Is there a more efficient way to do what I'm doing?