Command Palette

Search for a command to run...

Hectal
Phase 17: Interviews and Capstone
TypeScript · Exercise 1 of 6Next
Intermediate

Challenge: MyPick and MyReadonly

Write the generic types MyPick<T, K> and MyReadonly<T> so the two Expect lines in the starter compile. MyPick<Todo, 'title'> must be { title: string }, and MyReadonly<Todo> must equal the built-in Readonly<Todo>.

Do not remove the Equal and Expect helpers at the top: the checks use them. Do not use the built-in Pick or Readonly. A key that is not in the type (MyPick<Todo, 'owner'>) must be an error.

What Check tests

  1. Your code has no type errors
  2. MyPick works with two keys
  3. MyPick rejects a key that is not in the type
  4. MyReadonly makes assignment an error

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.