Currently, I am utilizing the OR operator within Typescript to designate that a product could be of type ProductI
OR CartResponseInterface.Product
This is how it is structured:
product: ProductI | CartResponseInterface.Product
However, when attempting to extract the id and assign it to a variable productId
like so:
productId = product.id || product.productId
I encounter the following errors:
Error 1:
Property 'id' does not exist on type 'ProductI | Product'.
Property 'id' does not exist on type 'Product'.ts(2339)
Error 2:
Property 'productId' does not exist on type 'ProductI | Product'.
Property 'productId' does not exist on type 'ProductI'.ts(2339)
In my product.model.ts file:
export interface ProductI {
id?: string;
name: string;
price: number;
.
.
.
}
In cart-response.model.ts:
export interface Product {
productId: string;
name: string;
totalPrice: number;
.
.
.
}
If anyone could provide assistance on resolving this issue, it would be greatly appreciated.