purescript-codec-argonaut icon indicating copy to clipboard operation
purescript-codec-argonaut copied to clipboard

addDefaultField should have Proxy version?

Open wclr opened this issue 4 years ago • 1 comments

To add missign prop we use:

addDefaultField "someProp" (encode C.string "") >~>

But "someProp" may not exist on the record type and it is not type-checked. Would it be possible (and better) to have typed-checked property names (using Proxy) and in thouse migration helpers? Or there is a reason why not typed string props used?

wclr avatar Jul 09 '21 09:07 wclr

addDefaultField doesn't operate on codecs for object/records (they work on the basic "any" Json type) so we can't do that with them in their current form. Adding a version that does use typing to better deal with this (and for the other field-related migrations) seems like a reasonable idea for sure though.

The reason for not making it just record/object typed is that these field migrations can also be used in situations where the resulting type is a variant or sum type, so requiring a record/object in the middle there can make things harder to deal with.

garyb avatar Jul 11 '21 14:07 garyb