This code:
open Webapi.Dom;
let el = Document.getElementById("outputSpan", document);
let () = switch (el) {
| Some(element) => Node.setTextContent(element, "It works!")
| None => ()
};
Gives this error:
3 │ let el = Document.getElementById("outputSpan", document);
4 │ let () = switch (el) {
5 │ | Some(element) => Node.setTextContent(element, "It works!")
6 │ | None => ()
7 │ };
This has type:
Dom.element (defined as
Dom.eventTarget_like(Dom._node(Dom._element(Dom._baseClass))))
But somewhere wanted:
Webapi.Dom.Node.t (defined as
Dom.eventTarget_like(Dom._node(Dom._baseClass)))
The incompatible parts:
Dom._element(Dom._baseClass)
vs
Dom._baseClass
In the ordinary JavaScript DOM world, all Element
s are Node
s, so I can do something like this:
var el = document.getElementById("outputSpan");
el.textContent = "It works!";
What am I missing here, and how do I get around this error message?