Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type newable<T> = new (cls: newable<T>) => T;
- export default abstract class AbstractFields<T extends AbstractFields<any>> {
- protected constructor(protected readonly cls: newable<T>) {
- }
- public with(property: keyof T & string, value: string | number): T {
- const newInstance: T = new this.cls(this.cls);
- for (const [k, v] of Object.entries(this)) {
- newInstance[k] = v;
- }
- newInstance[property as string] = value;
- return newInstance;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement