Lets say I have a com.google.gwt.dom.client.Document gwtDocument node and I want to convert it to a elemental2.dom.Document?
Since Document extends JavaScriptObject I assumed I could do something like:
elemental2.dom.Document elementalDoc = (elemental2.dom.Document)(gwtDocument);
However the elemental2 classes using jsinterop don't extend JavaScriptObject. So how do I convert between the two?
Thanks!
You can first cast to object, and then cast to the elemental type (1). This is a bit ugly, so there is a utility lib that can be used in GWT and J2CL called jsinterop-base. The
Jsutility can be used tocast(2) anduncheckedCast(3) any object. TheuncheckedCastshould be avoided and only used if you know what you are doing (ex. casting between iframes, or other special js situations).So in client code, you should use
Js.castto castGWTdom instances toelemental2instances.