restricciones de genéricos mecanografiados

// Restrict your generic type by using keyword extends
interface Length = {
  length: number;
};

function getLength<T extends Length>(arg: T) {
  return arg.length
}

getLength("Hi there!") // success
getLength([1,2,3]) // success
getLength(undefined) // error
getLength(67) // error
Stupid Scarab