I have following TS interface
export interface Item {
product: string | Product;
}
When I want to literate through array of items I have to eliminate the type. In other words
items = Items[];
items.forEach(item => {
item.product._id
})
is not going to work because property is is not appliable to strings. Hence I have to pre-check the type, i.e.:
items = Items[];
items.forEach(item => {
if (typeof item.product === 'object') item.product._id
})
I don't really like how it looks. How do you handle this situation?
Items'productproperties areProducts, notstrings, in which case allowing it in the original type seems pointless.