Search code examples
jquerykotlinkotlin-js-interop

Kotlin JS Overriding 'external' function with optional parameters error


I pulled in jQuery to use in my project using ts2kt. The basics work fine, however, I can't figure out how to call this function (I just want to pass a single callback to it):

fun done(doneCallback1: JQueryPromiseCallback<T>? = definedExternally /* null */, 
         vararg doneCallbackN: JQueryPromiseCallback<T>): JQueryPromise<T>

The JQueryPromiseCallback interface looks like this:

external interface JQueryPromiseCallback<T> {
    @nativeInvoke
    operator fun invoke(value: T? = definedExternally, vararg args: Any)
}

I tried creating an instance of it to pass in like this:

done(object : JQueryPromiseCallback<Any> {
    override fun invoke(value: Any?, vararg args: Any) {

    }
})

However, I'm getting an error on the invoke function:

Overriding 'external' function with optional parameters`

The @nativeInvoke annotation that was generated is also deprecated, and gives me a deprecation message that I can't figure out:

Use inline extension function with body using dynamic

Am I supposed to correct the file that ts2kt generated? If so, how? Do I just not have the syntax for overriding the invoke method right?


Solution

  • The best way now is to replace the interface with Kotlin’s function literal type, but the another problem is that we can’t correctly (in general) map it to Kotlin’s function literal type.

    Related issues: https://youtrack.jetbrains.com/issue/KT-16319 https://github.com/Kotlin/ts2kt/issues/55 https://github.com/Kotlin/ts2kt/issues/56