garyb / purescript-codec-argonaut

Bi-directional JSON codecs for argonaut
MIT License
39 stars 16 forks source link

addDefaultField should have Proxy version? #44

Open wclr opened 3 years ago

wclr commented 3 years ago

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?

garyb commented 3 years ago

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.