So, I have two situations in which a component needs a different type for each usage.
So, I have the base component...
const MyComponent = <T extends TypeA | TypeB,>({items}: {items: T[]}) => {
return (
<div>
{items?.map((item: T) => {
return (
<div>
/* Depending on the object, we get the value two different ways */
/*
THIS IS THE LINE THAT ERRORS... "sku.name" and "name.
Basically its saying the one value doesn't exist on the other object.
*/
<div className={nameClass}>{item.sku?.name || item.name}</div>
</div>
);
})}
</div>
And I use it like so:
<MyComponent<TypeA> items={[items]} />
And the other
<MyComponent<TypeB> items={[itemsWithTypeBShape]} />
I also tried "TypeA & TypeB", but then the error appears here: <MyComponent<TypeA> items={[items]} /> in the TypeA area.