Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. interface Type<T> {
  2. new (...args): T;
  3. }
  4.  
  5. interface Base {}
  6.  
  7. interface Identifiable {}
  8.  
  9. export function IdentifiableSubclass<T extends Base>(SuperClass: Type<T>) {
  10. class C extends (<Type<Base>>SuperClass) {
  11. // constructor(...args) {
  12. // super(...args);
  13. // return new Proxy(this, {
  14. // get(target, name) {
  15. // return target[name];
  16. // }
  17. // });
  18. // }
  19. }
  20. return <Type<Identifiable & T>>C;
  21. }
  22.  
  23. @Component({...})
  24. class HeroesComponent {
  25. constructor(public heroService: HeroService) {}
  26. }
  27. const HeroesComponentLogged = IdentifiableSubclass(HeroesComponent);
  28. export { HeroesComponentLogged as HeroesComponent };
  29.  
  30. class HeroService {
  31. public sayGoodbye() {
  32. console.log("Goodbye");
  33. }
  34. }
  35. class HeroComponent {
  36. constructor(public heroService: HeroService) {
  37. }
  38. }
  39.  
  40. const IdentifiedHeroComponent = IdentifiableSubclass(HeroComponent);
  41. let identified = new IdentifiedHeroComponent(new HeroService());
  42. identified.heroService.sayGoodbye();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement