0 of 7 problems solved0%
1 of 7

Pick a Preview

Pick<Type, Keys> creates a new object type by choosing a subset of properties. It’s great for lightweight summaries and list views. Keep runtime code thin: select fields and return a new object.

// Example: pick id and title from a larger shape
type Preview = Pick<
  { id: string; title: string; price: number },
  "id" | "title"
>;

Your Task

Create a small preview object from a full product.

  • Define type Product = { id: string; title: string; price: number; tags: string[] }.
  • Define type ProductPreview = Pick<Product, 'id' | 'title'>.
  • Implement function toPreview(p: Product): ProductPreview.
  • Return a new object containing only id and title.