Typescript: generic constraints

Example:

function getProperty(obj: T, key: K) {
  return obj[key];
}
Generics can be constrained to ensure type safety.

Solution:

// Use generic constraints to limit the types that can be passed to a function or method.

Beginner's Guide to TypeScript