I’m having trouble with translating this instantia...
# javascript
p
I’m having trouble with translating this instantiation of a class to kotlinjs
var ui = new firbeaseui.auth.AuthUI(firebaseI.auth());
. Doing the naive thing in kotlin does not result in a “new” call in the generated code e.g.
val ui = firebaseui.auth.AuthUI(firebase.auth())
does not work. rightnow I am doing the following, which works but is a bit ugly
Copy code
external val uiHack: AuthUI
val firebaseHack = firebase // firebase is imported as `@JsModule("firebase") external val firebase: Firebase`
val firbeaseUIHACK = firebaseui // same as above
js("var uiHack = new firbeaseUIHACK.auth.AuthUI(firebaseHack.auth());")
val ui = uiHack
the same question has also been asked on stackoverflow some time ago: https://stackoverflow.com/questions/49097351/cant-create-object-from-required-module-in-kotlinjs
for future reference the cleanest thing I was able to do is the following (from stackoverflow answer):
Copy code
val firebaseHack = firebase
val firbeaseUIHACK = firebaseui 
val ui: AuthUI = js("new firbeaseUIHACK.auth.AuthUI(firebaseHack.auth());")
We still need the
firebaseHack
variable to make sure firebase is available in the local scope in the generated js