Challenge 3

The instructions for this challenge are:

Implement the built-in Pick<T, K> generic without using it.

Constructs a type by picking the set of properties K from T

Example code that should compile correctly is provided:

interface Todo {
    title: string
    description: string
    completed: boolean
}

type TodoPreview = MyPick<Todo, 'title' | 'completed'>

const todo: TodoPreview = {
    title: 'Clean room',
    completed: false,
}

For this challenge I am not going to go into detail as it is basically the inverse of challenge 2. If the key is in the set described by K then we include the key otherwise we use never to omit it.

The eventual solution is this:

type MyPick<T, K extends keyof T> = { [P in keyof T as (P extends K ? P : never)]: T[P] };

Blog

Miscellaneous thoughts.