To my understanding, the only way to add that kind of safety is to implement a build plugin that analyzes your encoders.
The encoder code is perfectly valid because you might not want to encode everything from a record so, Elm will allow you to do that just like it will allow you to name those JSON field whatever you like (even misspelled names of your record fields) On Fri, Apr 7, 2017 at 8:37 AM, Andres Riofrio <[email protected]> wrote: > For example, I have the following code: > > type alias Account = > { id : Int > , name : String } > > -- ... in another module ... > > accountToJson : Account -> Json.Encode.Value > accountToJson act = Json.Encode.object > [ ("id", Json.Encode.int act.id) > , ("name", Json.Encode.string act.name) > ] > > If I add a field to Account, I'd like the compiler to make sure it won't > be skipped in the output JSON. The way I have written the encoder, the > compiler will happily let me skip the field in the serialized version of my > data. > > I thought about using destructuring like so: > > accountToJson : Account -> Json.Encode.Value > accountToJson {id, name} = Json.Encode.object > [ ("id", Json.Encode.int id) > , ("name", Json.Encode.string name) > ] > > > > But according to the documentation > <http://elm-lang.org/docs/records#pattern-matching>, this will compile > fine even if Account gains a new record. > > Any ideas on how to add this bit of type-safety to my application? > > -- > You received this message because you are subscribed to the Google Groups > "Elm Discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- There is NO FATE, we are the creators. blog: http://damoc.ro/ -- You received this message because you are subscribed to the Google Groups "Elm Discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
