Skip to content
Snippets Groups Projects
Select Git revision
  • 1b9931b06ac89b3283b6615c36a5ed969b3554b6
  • main default protected
  • polish
3 results

utils.h

Blame
  • Model.ts 524 B
    type Constructor<T> = new (...args: any[]) => T;
    
    
    abstract class Model extends Object {
        static createFromJson<T extends Object>(this: Constructor<T>, obj: any): T {
            const result = new this();
    
            Object.getOwnPropertyNames(obj).forEach(property => {
                if ( result.hasOwnProperty(property) ) {
    
                    (result as any)[property] = property.indexOf('Info') === -1 ? obj[property] : JSON.parse(obj[property]);
                }
            });
            return result;
        }
    }
    
    
    export default Model;