0 of 6 problems solved0%
5 of 6

Immutable Restock

A readonly field is an identifier that should not change. An optional number is either a number or missing. When you update an object, return a new object instead of changing the old one. This helps avoid surprises.

interface Item {
  readonly code: string;
  qty?: number;
}

You will raise the stock count and keep other fields the same.

Your Task

Increase stock without changing the original item.

  • Define interface Item { readonly sku: string; name: string; stock?: number }.
  • Implement restock(item: Item, amount: number): Item that returns a new object with stock increased by amount (use 0 when stock is missing).
  • Preserve all other fields and keep sku unchanged.