I'm facing an issue with a simple function that retrieves the address as a string
interface AddressType1 {
city: string | null;
state: string | null;
postalCode: string | null;
}
interface AddressType2 {
city: string | null;
region: string | null;
postalCode: string | null;
}
export const getAddressString = (
address: AddressType1 | AddressType2 | null,
): string => {
if (address != null) {
return `${address.city ?? ""}, ${address.region ?? address.state ?? ""} ${address.postalCode ?? ""}`;
}
return "";
};
However, TypeScript is throwing an error stating
Property 'region' does not exist on type 'RoadsideLocation'
and Property 'state' does not exist on type 'LocationGeocodedAddress'
.