> You don't actually care that it's a Dog BTW, just that it has a method called Bark(), if that's what you call on it.
This is exactly where TypeScript helps.
With the way TypeScript interfaces work, you can define an interface
interface Barker {
Bark();
}
And have an array of Barkers where each object's class doesn't have to explicitly say that it implements Barker. Ex.
class Dog {
Bark() {console.log('woof');}
}
class Cat {
Meow() {console.log('meow');}
}
var barkers: Barker[]; // array of Barkers
barkers.push(new Dog()); // compiles
barkers.push(new Cat()); // won't compile
Here Dog doesn't have to explicitly declare that it implements Barker. The TypeScript compiler automatically verifies that it does by the fact that it has a Bark() method.
In TypeScript, Arrays already support this level of type checking. With generics, the static type checking will be able to cover a lot more code so that you don't have to depend on writing tests.