Concept
keyof T is the union of the property names of T. With extends, a type parameter can be limited to those keys, so a function that reads obj[key] returns the right type for that key.
The tutor works through these with you, in conversation and code. A session ends when you have shown them, not when a video does.
A few lines that show keyof constraints doing its job.
function pluck<T, K extends keyof T>(obj: T, key: K): T[K] {
return obj[key];
}
const user = { id: 7, name: "Ada", active: true };
const name = pluck(user, "name"); // string
const id = pluck(user, "id"); // number
pluck(user, "email"); // error: not a key of userTyping the key parameter as string. obj[key] is then an implicit any (or an error under noImplicitAny), and misspelled keys pass the compiler.
Your roadmap puts these before keyof constraints, unless you already know them.
Once a session shows you understand keyof constraints, it comes back for review. Each review takes a minute and tells the memory model how well you still know it.
What you are asked on review day.
What does `K extends keyof T` constrain?
K may only be one of the property names of T — so get<T, K extends keyof T>(obj: T, key: K) rejects keys that do not exist on obj at compile time.
Topics that build on keyof constraints.