Advertisement
Guest User

Untitled

a guest
Jan 28th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. type Constructor<T = {}> = new (...args: any[]) => T;
  3.  
  4. interface Properties <TBase> {
  5.     value: TBase
  6. }
  7.  
  8. function ResponseObject<TBase extends Constructor>(Base: TBase): TBase {
  9.     return class extends Base implements Properties<TBase> {
  10.         public value: TBase;
  11.  
  12.         constructor (...values: any[]) {
  13.             let thisType = typeof values[0];
  14.  
  15.             if (thisType == "object" ||
  16.                 thisType == "number"  ||
  17.                 thisType == "boolean"
  18.             ) { super(values[0]); }
  19.  
  20.             if (Base.toString() == "Array") {
  21.                 super(...values);
  22.             }
  23.  
  24.             this.value = values[0];
  25.         }
  26.  
  27.         public toBlaze(): string{
  28.             return "OK!";
  29.         }
  30.     }
  31. }
  32.  
  33. const Responsed = ResponseObject(Number);
  34. const Res = new Responsed(56.02323);
  35. console.log(Res.toBlaze());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement