Developing an Angular 2+ application using TypeScript.
I've been structuring objects for storage in a data source, including helper methods within them. I have successfully saved these objects. ORIGINAL CLASS DESIGN EXAMPLE
export class Order {
readonly orderNumber: string;
amount: number;
shortCode: string;
readonly dateCreated: string;
constructor(){
this.orderNumber = cuid();
this.dateCreated = moment().format();
}
incrementAmount(): void {
this.amount += 1;
}
RESULTED OBJECT:
{
amount: 74.22,
dateCreated: '2017-04-03T21:23:49-04:00',
orderNumber: 'cj12v2rf50000zoguviraoik9',
shortCode: 'SJLLDE'
}
However, upon retrieval, the objects are not in their original form. It seems counterintuitive to manually extract and rebuild objects field by field. Instead, working with one known object might be more efficient for type usage and enhanced functionality.
Is it common practice in this ecosystem to transform returned data from services back into original objects?
If so, are there any resources available that discuss common approaches for achieving this?