This works with legacy backend but not with IR: ``...
# javascript
r
This works with legacy backend but not with IR:
Copy code
external interface BtOn {
}

interface SnOn<T> : BtOn {
    var self: T
}

@Suppress("UnsafeCastFromDynamic")
fun on(target: Any): SnOn<Any> {
    val obj = js("{}")
    obj["self"] = target
    return obj
}

fun main() {
    val x = on("test");
    console.log(x.self);
}
It fails with
x._get_self_ is not a function
. Is it a bug in the compiler backend or is my code just wrong?
d
Your code is wrong, as you are relying on compiler internals (
self
property is translated to a JS property named the same). You have to use
external interface
to describe raw JS objects.
🙏 1
a
Actually that's an IR bug. This should work out of the box. You should mark
SnOn<T>
as an
external interface
just as a workarround. This same problem is being faced by the
kotlin-react
js wrapper and they gave that workaround
d
How is it an IR bug?
interface
describes a full-blown instance of a class. Not just any random object with some properties.
a
This link https://kotlinlang.slack.com/archives/C0B8L3U69/p1585318146030900, explains why (though in another context apart from this)