Last active
March 18, 2020 20:04
-
-
Save FFKL/09f056b4e2c224cb8de20d745bc52921 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // @flow | |
| class Animal {} | |
| class Dog extends Animal { | |
| bark() {} | |
| } | |
| class Cat extends Animal { | |
| meow() {} | |
| } | |
| const dogs: Dog[] = [new Dog(), new Dog()]; | |
| const animals: Animal[] = dogs; // Cannot assign `dogs` to `animals` because `Dog` [1] is incompatible with `Animal` [2] in array element | |
| animals.push(new Cat()); | |
| dogs.forEach(d => d.bark()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Animal {} | |
| class Dog extends Animal { | |
| bark() {} | |
| } | |
| class Cat extends Animal { | |
| meow() {} | |
| } | |
| const dogs: Dog[] = [new Dog(), new Dog()]; | |
| const animals: Animal[] = dogs; | |
| animals.push(new Cat()); | |
| dogs.forEach(d => d.bark()); // TypeError: d.bark is not a function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment