I was going over the documentation on Advanced Types in Typescript (found here: https://www.typescriptlang.org/docs/handbook/advanced-types.html) and it mentioned the Index Query Operator and gave the following as an example:
function pluck<T, K extends keyof T>(o: T, names: K[]): T[K][] {
return names.map(n => o[n]);
}
I understand how keyof produces a union of all known public property names on object T but I don't exactly understand what role the extends plays. I get that it's saying that K must be a valid property of T but why is extends used and not something else? Also, is it possible to extend unions in Typescript or is this more of a semantic specific to generics?
Thanks.