Open andriygm opened 1 year ago
Hmm, I just took a proper look at this and I'm not sure if we can make an improvement here.
We should definitely add XMLDocument
, I'm about to open a PR that does that. Update: https://github.com/scala-js/scala-js-dom/pull/804
However, it is difficult to refine the return type of parseFromString
based on its arguments. This is a very common problem: for example document.createElement("div")
is returning an HTMLDivElement
but we are not reflecting that in the type. For the user, the solution is simply to do an asInstanceOf
cast.
In the future if we dropped support for Scala 2 (or split sources across Scala 2/3) we could possibly do something interesting with literal types. That is tracked in this issue:
Is parseXMLFromString
too unwieldy?
parseXMLFromString
is not a real method in the DOM APIs. We only facade the raw APIs (warts and all), and leave it up to other libraries to solve the usability issues.
For example see: https://github.com/raquo/scala-dom-types#what-about-scala-js-dom
Currently,
DOMParser
'sparseFromString
method returns aDocument
type when using MIME type"text/xml"
. We should instead return anXMLDocument
. It doesn't look like theXMLDocument
type exists, so that should be created as well.