Migration of js_of_ocaml code

Hello,

I’m updating some old code written with js_of_ocaml, and I have an error in the compilation with the latest library. This small part of the code does not compile anymore:

open Js_of_ocaml

type message = unit
type worker = (Js.js_string Js.t, message) Worker.worker Js.t

let () =
  let (worker : worker) = Worker.create "" in

  let handler : (_, (_, _) Dom_html.messageEvent Js.t) Dom_html.event_listener =
    Dom.handler (fun (event : message Worker.messageEvent Js.t) -> Js._true)
  in
  worker##.onmessage := handler

The relevant part of the error message is this part:

Type
         ('c, 'd) Worker.worker Js.t Js.opt Js_of_ocaml__.Js.readonly_prop =
           < get : ('c, 'd) Worker.worker Js.t Js.opt > Js.gen_prop
       is not compatible with type
         Dom_html.element Js.t Js.opt Js_of_ocaml__.Js.readonly_prop =
           < get : Dom_html.element Js.t Js.opt > Js.gen_prop
…
The second object type has no method onerror

Is this something I have to update on my side?

This is a known consequence of a 6.5 change: the various messageEvent types were merged into ('target, 'data) Dom_html.messageEvent, and Worker.onmessage now gives the handler the worker itself as event target.

try to remove type annotation on event

 Dom.handler (fun event -> ...)

or update it to

 Dom.handler (fun (event : (_, message) Dom_html.messageEvent Js.t) -> ...)

Perfect! Thank you for the answer!