Typing and js_of_ocaml

Hi !

I got a little problem with typing and js_of_ocaml. Consider this code:

let onload _ =
let d = Html.document in
let input = d##getElementById (Js.string "css") in
let output = d##getElementById (Js.string "minified") in

let inputText = Js.Opt.get
    (Js.Opt.bind input Html.CoerceTo.textarea) (fun _ -> assert false) in
let outputText = Js.Opt.get
    (Js.Opt.bind output Html.CoerceTo.textarea) (fun _ -> assert false) in

ignore (Html.addEventListener (Js.Opt.get input (fun _ -> assert false))  Html.Event.input 
                    (Html.handler (fun _ ->
                        let content = inputText##value in
                        let minified = minify (explode (Js.to_string (content))) in
                        outputText##value := Js.some (Js.string (implode minified));
                        Js._true
                    ))
                    Js._true);
Js._false

This code returns me this error:

File "css.ml", line 51, characters 42-58:
51 |                             let content = inputText##value in
                                               ^^^^^^^^^^^^^^^^
Error: This expression has type
         Js.js_string Js.t Js_of_ocaml__.Js.prop =
           < get : Js.js_string Js.t; set : Js.js_string Js.t -> unit >
           Js.gen_prop
       but an expression was expected of type 'res Js.meth

The fact is, I can’t access to the field “value” even if inputText and outputText are typed as “textarea”.
Why ? Am I doing something wrong with typing ?

I think the error is trying to point at the fact that you are calling value as a method but that is instead a value. Does it work if you write inputText##.value instead?

1 Like