Command Palette

Search for a command to run...

Hectal
Phase 10: Utility Types and Type-Level Patterns
TypeScript · Exercise 1 of 5Next
Intermediate

A Patch Type from Utilities

A server accepts a patch for a user: the id is always required, and every other field is optional. The type UserPatch doesn't exist yet, so the Types panel shows an error.

Write type UserPatch using only built-in utility types (Pick, Omit, Partial). The function applyPatch and the variable u are already written. The checks call applyPatch with good and bad patches.

What Check tests

  1. Your code has no type errors
  2. The console prints the patched user
  3. A patch with only id and email is accepted
  4. A patch without id is rejected
  5. A patch with an unknown field 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.