I have this code as an example :
productsWithCategory$ = combineLatest([
this.products$,
this.productCategoryService.productCategories$
]).pipe(
map(([products, categories]) =>
products.map(product => ({
...product,
price: product.price ? product.price * 1.5 : 0,
category: categories.find(c => product.categoryId === c.id)?.name,
searchKey: [product.productName]
} as Product))
),
shareReplay(1)
);
I want to know how this part works with the spread operator ... ?
products.map(product => ({
...product,
price: product.price ? product.price * 1.5 : 0,
category: categories.find(c => product.categoryId === c.id)?.name,
searchKey: [product.productName]
} as Product)
as far as I understand the operator ... will copy the old object properties to a new object, but why when we add price again it still works ? doesn't it mean that now we have 2 properties "price" in that object ?
