how do I declare an external class on a namespace?...
# javascript
n
how do I declare an external class on a namespace? Do I need to create a package for it or is there some other way?
k
did you try to write
external class C
?
Ah, I see
@JsQualifier
n
ah yea, awesome, thank you 🙂
n
hm one last stupid question, i have a plain non modular .js that i include that has some api i need to call, but if i mark it as JsNonModule I cannot call it from kotlin, is there any way to override this? Or can I only call from modules?
k
Don't mark it as JsNonModule.
n
but then when i load the code it tries to get it from a module, and crashes, is there any way to just tell kotlin it will be available at runtime and that it shouldnt load it?
k
Don't mark it as JsModule
n
I have done neither
i only put the jsqualifier
so i could make the external declarations
k
I have no idea what you are exactly doing, so I can't help you. Can you share your example?
n
yea sure
i have a script tag in my html including the chromecast api, and then i have the following in my kotlin
Copy code
@file:JsQualifier("chrome.cast")
package my.pkg

external class SessionRequest(applicationID: String)

external class ApiConfig(sessionRequest: SessionRequest, sessionListener: (dynamic) -> Unit, receiverListener: (dynamic) -> Unit)

external fun initialize(apiConfig: ApiConfig, success: () -> Unit, error: (dynamic) -> Unit)
these 3 are all available globally as chrome.cast.X
but when loading my bundle it initially tries to do
var initialize = chrome.cast.initialize;
which fails as it does it only for the modules i have included
oh wait, i guess i could just define it from window.chrome.cast
yea that works, sorry to bother you, and thanks for the all the help 🙂