MrWolfZ/ngrx-forms

Boxing Date object results in Error.

AlyxEsson opened this issue · 2 comments

Library version:
"ngrx-forms": "^6.3.5",

Describe the bug
When Boxing an interface which contains a property with a Date type, the box function throws an error A form control value must be serializable

To Reproduce

export interface MyModel{
    name:string;
    dob:Date;
}
const value:MyModel = {name:'Bob', dob: new Date()}
box(value) //==> Throws error

I hoped that boxing would be able to handle this situation. I'm afraid that i might need to restructure our models and that would take a huge chunk of time.

This error is correct. Date objects are not serializable, which can cause issues. Serializable basically means this:

value === JSON.parse(JSON.stringify(value))

Instead of boxing dates I recommend you use a value converter and store dates as ISO strings. There's an example for how to do this in the example app.

Thanks for the fast response.
Really appreciate it