Command Palette

Search for a command to run...

Hectal
Phase 10: Utility Types and Type-Level Patterns
TypeScript · Exercise 2 of 5 PreviousNext
Advanced

Write PickByValue

Write PickByValue<T, V>: a type that keeps only the properties of T whose value type fits V. Use a mapped type with an as clause that remaps non-matching keys to never.

The starter returns T unchanged, so the examples below don't type-check yet. The checks use Product and a few assignments of their own.

What Check tests

  1. Your code has no type errors
  2. The console prints the numbers
  3. The text fields are title and sku
  4. A non-number property is rejected from the numbers
  5. A missing text property is rejected

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.

Console

Nothing printed yet.