0 of 7 problems solved0%
3 of 7

Merge with Partial

Partial<T> makes all properties optional. It’s useful for patch objects where only changed fields are sent. Merge the patch over the base and return a new object so callers can keep the original.

// Example: apply a partial update
type Patch = Partial<Product>;

Your Task

Apply a partial update to a product without mutation.

  • Define type Product = { id: string; stock: number; price: number; featured?: boolean }.
  • Implement function applyPatch(p: Product, patch: Partial<Product>): Product.
  • Return a new object with shallow-merged fields (patch wins).
  • Do not mutate p; preserve unspecified properties.