I'm using angular 7 (I guess it's the same for ver. 2.x) and I'm using something similar to httpClient.get<Hero[]>(url)
with no other processing. Hero
has also the dateOfBirth
property which has the type Date
; when obtaining the Hero
array I see that the typeof dateOfBirth
is string
instead of Date
.
Is that normal or not? how could one solve it (I mean getting somehow Date
)?
PS1: I'm not looking for some manual conversion by using e.g. the RxJs map
operator because I might have a tree of objects with many properties facing the same problem so using map
would mean too much work
PS2: for the moment I'm solving the problem doing somewhere (a RxJs tap
on that httpClient.get
) in the code this:
if (typeof hero.dateOfBirth === 'string') {
hero.dateOfBirth = new Date(hero.dateOfBirth);
}
The received JSON
is e.g.:
"dateOfBirth" : "2018-12-17T20:04:32.721+0000"