metz-sh / simulacrum

Code-playground to visualise complex engineering flows.
https://metz.sh
Apache License 2.0
400 stars 28 forks source link

Interfaces don't work #32

Open iostreamer-X opened 2 months ago

iostreamer-X commented 2 months ago

If we had an interface for example:

interface Animal{
  walk(): void;
}

And then we have a class like:

class Main {
  private animals = [new Dog(), new Cat()];

  randomWalk() {
    const index = Math.round(Math.random());
    const animal = this.animals[index];

    // This doesn't work
    animal.walk();
  }
}

Then animal.walk will not work at all. The compiler completely skips it since it sees just an interface and not a concrete class.