1

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?

4

1 回答 1

1

现在最好的方法是将接口替换为 Kotlin 的函数字面量类型,但另一个问题是我们不能正确(通常)将其映射到 Kotlin 的函数字面量类型。

相关问题: https ://youtrack.jetbrains.com/issue/KT-16319 https://github.com/Kotlin/ts2kt/issues/55 https://github.com/Kotlin/ts2kt/issues/56

于 2017-08-08T19:51:52.590 回答