This file returns edges either as an array of objects or a singular object.
However, TypeScript doesn't accept my attempts at suggesting it could be an array or not.
As it is here, it errors on the map function - if I set edges in CategoriesProps to an array, then it errors on categories.edges.node.name
Any ideas on how to progress?
Thanks
type CategoriesProps = {
categories: {
edges: {
length: number;
node: {
name: string;
};
};
};
};
export default function Categories({ categories }: CategoriesProps) {
return (
<span className="ml-1">
under
{categories.edges.length > 0 ? (
categories.edges.map((category, index) => (
<span key={index} className="ml-1">
{category.node.name}
</span>
))
) : (
<span className="ml-1">{categories.edges.node.name}</span>
)}
</span>
);
}