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?

2
  • Feel free to correct generated file, ts2kt is very buggy. But actually, JQuery is already in kotlin standard library Commented Aug 4, 2017 at 8:12
  • The jQuery in the standard library is deprecated, and it seems to contain only parts of it. Commented Aug 4, 2017 at 8:14

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.