Closed mfredix closed 1 year ago
Given this code
const myDate = new Date(); const justDate = Maybe.of(myDate); const myObject = { field: justDate }; const myNestedObject = { field: Maybe.of( {nested: myDate}) }; console.log(JSON.stringify(myDate)); console.log(JSON.stringify(justDate)); console.log(JSON.stringify(myObject)); console.log(JSON.stringify(myNestedObject)); console.log(JSON.stringify(justDate) === JSON.stringify(Maybe.of(new Date('1995-12-17T03:24:00'))));
, using purify-ts 1.3.0. the output is something like
"2022-10-28T16:09:09.534Z" {} {"field":{}} {"field":{"nested":"2022-10-28T16:09:09.534Z"}} true
I guess one can argue about what the expected JSON should be, but dropping the timestamp info is confusing and could generate subtle bugs.
This is indeed some very strange behaviour in toJSON. I've added an explicit check for dates because I couldn't find any other workaround.
toJSON
Given this code
, using purify-ts 1.3.0. the output is something like
I guess one can argue about what the expected JSON should be, but dropping the timestamp info is confusing and could generate subtle bugs.