SHARE
TWEET

Untitled

a guest May 23rd, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. type newable<T> = new (cls: newable<T>) => T;
  2.  
  3. export default abstract class AbstractFields<T extends AbstractFields<any>> {
  4.     protected constructor(protected readonly cls: newable<T>) {
  5.     }
  6.  
  7.     public with(property: keyof T & string, value: string | number): T {
  8.         const newInstance: T = new this.cls(this.cls);
  9.  
  10.         for (const [k, v] of Object.entries(this)) {
  11.             newInstance[k] = v;
  12.         }
  13.         newInstance[property as string] = value;
  14.  
  15.         return newInstance;
  16.     }
  17. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top