Currently, I have numerous entities that have been defined:
export class Meeting implements IHasId {
id = 0;
locationId = 0;
meetTime = new Date();
isFinalized = false;
imageId: number = null;
description = '';
name = '';
}
Alongside this, I utilize a generic crud service that is responsible for resolving these entities to their original type
export class ApiResourceBaseService<T extends IHasId> {
get(id: number): Observable<T> {
return this.http.get<T>(`${this.apiUrl}/${this.route}/${id}`);
}
}
Although Typescript Generics are quite useful, there is an issue when I call get<T>
as Typescript incorrectly assumes that my JSON data is accurate. This results in my date objects being resolved as strings instead of dates.
Given the multiple entities I have, it becomes tedious to create custom constructors/adapters to parse the dates.
Does anyone have a more efficient solution to automatically resolve dates?