Skip to content

Instantly share code, notes, and snippets.

@jordaaash
Created October 18, 2016 00:29
Show Gist options
  • Save jordaaash/a340bf42c2d00b397c8e9081cbe924ae to your computer and use it in GitHub Desktop.
Save jordaaash/a340bf42c2d00b397c8e9081cbe924ae to your computer and use it in GitHub Desktop.
Decorator Pattern with generics in Flow (not working)
// @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