Closed arnaud-secondlayer closed 1 month ago
They should both work, but the first one is preferred so that you're not relying on the behavior of toString
. As for code size/performance, they should be similar e.g.
// dart2js
A._asString(t1._as(_this.innerHTML)) // first
J.toString$0$(t1._as(_this.innerHTML)) // second
Both do a typeof
check but the second one goes through roughly an extra call to intercept the type. In dart2wasm, they should also be similar in performance/code-size (one interop call to convert a JS string to a Dart String
)
For context on why this needed to be a JSAny
: this API can possibly return a TrustedHTML
instead of a string.
Thanks
HTMLDivElement
functioninnerHTML
returnsJSAny
. I'd like to convert it to a darlangString
.What is the preferred solution? I can think of two, but there could be others as well.
My criterion for preferred solution would probably be that the generated javascript is the simplest possible.