Can anyone explain to me why i can only unsafe typ...
# javascript
c
Can anyone explain to me why i can only unsafe type cast the link element here?
Copy code
fun reloadCss() {
    val iframe = document.getElementById("iframe-id")
    println("Test0")
    if (iframe != null && iframe is HTMLIFrameElement) {
        val contentWindow = iframe.contentWindow
        if (contentWindow == null) {
            println("Null1")
            return
        }
        val link = contentWindow.document.getElementById("css-link")
        if (link == null) {
            println("Null2")
            return
        }
        console.log("Typeof is" + jsTypeOf(link))
        console.log(link::class)
        if (link is HTMLLinkElement){
            val href: String = link.href.split('?')[0]
            link.href = "$href?version=${currentTimeMillis()}"
            println("Test1")
        }
        val cssLink = link.unsafeCast<HTMLLinkElement>()
        val href: String = cssLink.href.split('?')[0]
        cssLink.href = "$href?version=${currentTimeMillis()}"
        println("Test2")
    }
}
When the code above is executed the console output is as follows:
It some how does seem to know that it is a HTMLLinkElement but can't cast to it. If it is helpul, I am using the IR compiler.