Monomorphic client values

I’m an Eliom beginner and get the error “The types of client values must be monomorphic from its usage or from its type annotation”. Here is my current example:

let%server add_item_form =
  let open Html.D in
  let inp = Raw.input ~a:[a_input_type `Text] () in
  let btn = Raw.button ~a:[a_class ["button"]] [txt "add"] in
  ignore
    [%client
      let open Html.D in
      let open Js_of_ocaml_lwt.Lwt_js_events in
      let inp = Html.To_dom.of_input ~%inp in
      (Lwt.async @@ fun() ->
        clicks (Html.To_dom.of_element ~%btn)
        (fun _ _ ->
          let v = inp##value |> Js_of_ocaml.Js.to_string in
          add_item {id="3";name=v;description=""};
          Lwt.return_unit):unit
      )];

  div [
    inp;btn
  ]

I assume, there is a problem with ~%inp and ~%btn. I wonder why I get this error, the code is similar like in the tutorials. What am I doing wrong?

You can fix this by annotating the client value:

  let _ : unit Lwt.t Eliom_client_value.t = [%client ...] in

Then you’ll need to use the valueattribute instead of a non-existing method:

          let v = inp##.value |> Js_of_ocaml.Js.to_string in

Hope it helps!

Thank you! It’s working now.