Created
October 18, 2016 00:29
-
-
Save jordaaash/a340bf42c2d00b397c8e9081cbe924ae to your computer and use it in GitHub Desktop.
Decorator Pattern with generics in Flow (not working)
This file contains 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 SuperClass { | |
something () { | |
} | |
} | |
class SubClass extends SuperClass { | |
} | |
function decorateWithSomethingElse <T: Class<SuperClass>> (SuperClass: T): T { | |
return class SomethingElseAdded extends SuperClass { | |
addSomethingElse () { | |
} | |
} | |
} | |
var SubClassWithSomethingElse = decorateWithSomethingElse(SubClass) | |
// (new SubClass) instanceof SuperClass -> true | |
// (new SubClassWithSomethingElse) instanceof SubClass -> true | |
// (new SubClassWithSomethingElse) instanceof SuperClass -> true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment