class Person {
constructor(public name: string) {}
}
class Manager extends Person {}
class Admin extends Person {}
class School {
constructor(public name: string) {}
}
function doOperation<T extends Person>(person: T): T {
return person;
}
let person = doOperation(new Manager("tars"));
let school = doOperation(new School("Harper's"));
One interesting aspect of TypeScript to consider is why no error is thrown in the case where a School instance is passed to doOperation, even though School is not a subclass of Person. Perhaps this behavior can be attributed to both classes (Person and School) having properties with the same name.