For some reason I can not run my React app, because following error:
TypeScript: Property 'name' does not exist on type 'any[]'.
I am exporting my TS type based on my API data:
export type CartItemType = {
id: number;
name: string;
image: string;
amount: number;
chair: {
name: string;
colors: {
white: {
hex: string;
};
};
};
};
Fetching the data:
const getProducts = async (): Promise<CartItemType[]> =>
await (await fetch("apiEndpoint")).json();
const [cartItems, setCartItems] = useState([] as CartItemType[]);
const { data, isLoading, error } = useQuery<CartItemType[]>(
"products",
getProducts
);
I would like to select the fetched data and I am doing it in such a way:
const [selectedData, setSelectedData] = React.useState([]);
{data?.map((item) => (
<button onClick={() => setSelectedData(item)}>SHOW</button>
{selectedData === item ? (
<p>{selectedData.chair.description}</p>
) : null}
Unfortunately I am having this error on selectedData:
This condition will always return 'false' since the types 'any[]' and 'CartItemType' have no overlap.
I don't really know what that means and how to fix it.

It would work only when I would specify the number in object array like this:
selectedData[0].name
But I have to make it work for selectedData.name