The error you're encountering is due to TypeScript not being able to infer the correct type for propertyData. In your code, you've defined propertyData as an array when property is not available. However, you're trying to access priceCurrent property on propertyData which doesn't exist on an array type.
Here's the problematic line:
const propertyData = property ? property.data : [];
In this line, if property is not available, propertyData is set to an empty array. But later, you're trying to access priceCurrent on propertyData:
const priceCurrent = propertyData?.priceCurrent;
This is not valid because an array doesn't have a priceCurrent property.
To fix this, you should ensure that propertyData always has a type that includes priceCurrent. If property is not available, you could set propertyData to an object with a default priceCurrent value or null instead of an empty array.
Here's an example of how you could adjust your code:
interface PropertyData {
priceCurrent: number;
}
const propertyData: PropertyData = property ? property.data : { priceCurrent: 0 };
const priceCurrent = propertyData.priceCurrent;
In this adjusted code, propertyData is always an object with a priceCurrent property, so TypeScript won't throw an error when you try to access priceCurrent.
Please note that this is a general TypeScript issue and not specific to Astro. You might want to review TypeScript's type inference and type assertion features to better understand how to work with types in TypeScript.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: