Command Palette

Search for a command to run...

Hectal
Phase 14: TypeScript with React
TypeScript · Exercise 5 of 6 PreviousNext
Intermediate

A generic List<T>

The List component takes unknown items, so App can't read p.id or p.name in its callbacks. Make ListProps and List generic over T so getKey and renderItem receive the same type as items.

The checks use the component name List, the type Product, the array products and the container #shop.

What Check tests

  1. Your code has no type errors
  2. A List of numbers works with number methods
  3. A List of numbers rejects string methods
  4. A List of products rejects a property that doesn't exist
  5. The page shows three items, the first "Pen: 12"

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Your page

Press Run to see the page.

Console

Nothing logged yet.