typescript-object-helper
Version:
A simple dependency to aid in mapping and instantiating typescript classes
28 lines (27 loc) • 1.31 kB
TypeScript
/**
* Creates a class typed object from string input
*
* @param stringIn The json string we want to create a class object from
* @param classCast The class constructor we want to create
*/
export declare function instantiateFromJson<T>(json: Object, classCast: new () => T): T;
export declare function instantiateFromJsonReverseParam<T>(classCast: new () => T, json: any): T;
/**
*
* @param arrayIn The array of generic objects we want to create class objects from
* @param classCast The class constructor we want to create
*/
export declare function copyArray<T>(arrayIn: any, classCast: new () => T): T[];
/**
* Does a full copy on an object including nested objects and arrays (deep copy)
* Removes attributes that are not in the destination class model
* Also support typing of attributes and arrays. If you want a nested attribute typed (for access
* to it's functions) then add the @ClassCast decorator to the attribute in your model. example:
*
* @ClassCast(Employee)
* public employee: Employee = undefined;
*
* @param objectIn The generic object we want to create a class object from
* @param classCast The class constructor we want to create
*/
export declare function copyObject<T>(objectIn: Record<string, any>, classCast: new () => T, allowExtras?: boolean): T;