Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement