anchor.diff:                      | _ -> failwith "Invalid field option kind")
                   o))
   
  -    let Union _ (discr: string) (cases: (string * (string * string * (unit -> obj -> obj))[])[]) =
  +    let Union _ (discr: string) (cases: (string * (string * string * (unit -> obj -> obj) * OptionalFieldKind)[])[]) =
           box (fun () ->
               box (fun (x: obj) ->
                   if JS.TypeOf x ===. JS.Object then
  
positive.code:         box (fun () ->
              box (fun (x: obj) ->
                  let o = if t ===. JS.Undefined then New [] else JS.New t
                  fields |> Array.iter (fun (name, enc, kind) ->
                      match kind with
                      | OptionalFieldKind.NotOption ->
                          o?(name) <- enc () x?(name)
                      | OptionalFieldKind.NormalOption ->
                          o?(name) <-
                              if JS.HasOwnProperty x name
                              then Some (enc () x?(name))
                              else None
                      | OptionalFieldKind.MarkedOption ->
                          if JS.HasOwnProperty x name then
                              o?(name) <- (enc () x?(name))
                      | _ -> failwith "Invalid field option kind")
                  o))
  
      let Union (t: obj) (discr: string) (cases: (string * (string * string * (unit -> obj -> obj))[])[]) =
          box (fun () ->
              box (fun (x: obj) ->
                  if JS.TypeOf x ===. JS.Object then
  
negative.code:                                 if JS.HasOwnProperty x k then r := discr?(k); true else false)
                              !r
                      o?("$") <- tag
                      cases.[tag] |> snd |> Array.iter (fun (from, ``to``, dec, kind) ->
                          match from with
                          | null -> // inline record
                              o?("$0") <- dec () x
                          | from -> // normal args
                              match kind with
                              | OptionalFieldKind.NotOption ->
                                  o?(from) <- dec () (x?(``to``))
                              | OptionalFieldKind.NormalOption ->
                                  o?(from) <-
                                      if JS.HasOwnProperty x ``to``
                                      then Some (dec () x?(``to``))
                                      else None
                              | _ -> failwith "Invalid field option kind")
                      o
                  else x // [<Constant>]
              ))
  