Date field transmitted as json not converted to Date #7499
Unanswered
arnaud16571542
asked this question in
Q&A
Replies: 1 comment 1 reply
-
@arnaud16571542 , Date type do not exist at run time, so when running this piece of code it is not showing Date (since it does not exists, rather it shows its corresponding type What you can do at compile-time is to use type-guard functions as explained here using-type-predicates . function isValidDate(d) {
return d instanceof Date && !isNaN(d);
} Be asure however, that loopback4 will check the content upon request, that's the function for the parser |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello everyone,
I have a stupid question i'm struggle with.
My Nuxt/Axios front-end do a JSON post request to my loopback backend : using a DTO model object which contain a Date field.
Axios convert all the objects to JSON. The date field is converted to something like '2021-05-20T09:54:47.849Z'.
My problem is : this date, declared on loopback as type:'date'/javascript as Date, is filled as string in the DTO object and not as Date during parsing. This cause cast problem lately in the controller.
I don't have this problem for boolean value. So, for me, this doesn't seem the correct behaviours for Date fields. Probably i miss a configuration, but I can't find it :(
Any idea ? Thank you for your help !
Beta Was this translation helpful? Give feedback.
All reactions