Hey when I map a Kotlin object to some JS via Exte...
# javascript
k
Hey when I map a Kotlin object to some JS via External, etc and the JS is loaded via async. I get
Uncaught ReferenceError: google is not defined
. Is there a way to remove kotlin's safety check for external JS?
r
Hi there, seems like you are getting VM (not Kotlin) error, so there is no check you can suppress. Could you please provide some details?
k
The error is in JavaScript and the error is when the compiled Kotlin checks to see if my external class exists
Essentially I want to mock a Javascript library in Kotlin, but load the library in dynamically
r
Is there anything like nested class or enum in your external declaration? It would be good if you post a minimal example of you problematic code.
k
Copy code
@file:JsQualifier("google.maps")
package org.something

import org.w3c.dom.HTMLElement

@JsName("Map")
external class GoogleMap(htmlElement: HTMLElement, options: dynamic)
Is the class
r
Copy code
@JsName("google")
external object Google {
    @JsName("maps")
    object Maps {
        @JsName("Map")
        interface GoogleMap {
        }
    }
}

inline fun Google.Maps.GoogleMap(htmlElement: HTMLElement, options: dynamic): Google.Maps.GoogleMap {
    return js("new google.maps.Map(htmlElement, options)").unsafeCast<Google.Maps.GoogleMap>()

}
Could you please try this code. Here we define inline function which looks like constructor but takes in the account async loading.
k
😄 Awesome! This worked. Thank you so much!