I am aware of the fact that interfaces has no real effect on data at run time in Angular2. Although I would like in some way to cast my fetched data to the correct types, and this is my solution for now:
return this.http.get('/api/events')
.map(res => {
var events = <Event[]>res.json();
for(var event of events) {
event.time = new Date(event.time);
}
return events;
})
Because the angular application requires some fields in the event (here, the time as an example) to be in the correct types, I found out this solution. It is not that smooth as I would like it to be, but I am not sure there is another way to do it either. What I want is simply to map the value of event.time in each event to a Date object.
Do I have the best solution or is there a better one out there?