Я использую оператор ИЛИ в Typescript, чтобы определить, что продукт может иметь тип ProductI
ИЛИ CartResponseInterface.Product
Структурирован как
product: ProductI | CartResponseInterface.Product
Но когда я пытаюсь получить идентификатор и сохранить его в переменной productId
как
productId= product.id || product.productId
Я получаю нижеуказанные ошибки
Error:1
Property 'id' does not exist on type 'ProductI | Product'.
Property 'id' does not exist on type 'Product'.ts(2339)
Error2:
Property 'productId' does not exist on type 'ProductI | Product'.
Property 'productId' does not exist on type 'ProductI'.ts(2339)
product.model.ts
export interface ProductI {
id?: string;
name: string;
price: number;
.
.
.
}
корзина -response.model.ts
export interface Product {
productId: string;
name: string;
totalPrice: number;
.
.
.
}
Может кто-нибудь сказать мне, как решить эту проблему?