class Animal {}
class Cat extends Animal { meow() {} }
class Dog extends Animal { woof() {} }
function foo(animals: Animal[]) {
animals.push(new Dog)
}
const cats: Cat[] = [new Cat];
foo(cats);
https://www.typescriptlang.org/play/#code/MYGwhgzhAECCB2BLAt...