0 of 7 problems solved0%
4 of 7

Readonly Snapshot

Readonly<T> marks properties as non-writable at the type level. ReadonlyArray<T> marks the array as non-mutable. While the runtime objects are still plain JS, these types prevent accidental writes during development.

// Example: a readonly view of items
function snapshot(items: T[]): ReadonlyArray<Readonly<T>>;

Your Task

Create a readonly snapshot of products.

  • Define type Product = { id: string; name: string; price: number }.
  • Implement function snapshot(items: Product[]): ReadonlyArray<Readonly<Product>>.
  • Return a new array with new objects (spread each item).
  • Do not mutate the input array or its elements.