This should have been simple but, when defining an interface with options type:
options:
Array<{
title?: string;
options: Option[];
}>
| Option[];
I'm using map function to loop over the array, something like this:
{options.map((option) => (
<SelectPrimitive.Group key={option.title}>
Then I won't be able to access option.title, ts will say this title property doesn't exist. But the moment I remove the second part of the union:
options:
Array<{
title?: string;
options: Option[];
}>
It will work. Why doesn't ts understand that it's a union type, and instead it selects the second part of the union?