Creating a cohesive type for cart items and their addons is essential. Both entities should share common keys:
type CartItem = {
productId: string
name: string
description: string
unitPrice: number
netTotal: number
quantity: number
taxTotals?: { [key: string]: string }[]
addons:[
addonId: string
name: string
description: string
unitPrice: number
netTotal: number
quantity: number
taxTotals?: { [key: string]: string }[]
]
}
Exploring the use of a specific type for cart items was attempted using intersection types, but uncertainty lingers:
export type CartItemEntity = {
productId: string
addonId:string
name: string
description: string
unitPrice: number
netTotal: number
quantity: number
taxTotals?: { [key: string]: string }[]
period: PeriodInfo
}
type CartType = Omit<CartItemEntity, 'addonId'> & { addons?: Omit<CartItemEntity, 'productId'>[] }
The approach seems incomplete, as accessing keys through IDE hover does not provide clarity. Is there a more robust method to tackle this scenario?