I pulled in jQuery using ts2kt. It generated an in...
# javascript
z
I pulled in jQuery using ts2kt. It generated an interface like this:
Copy code
external interface JQueryPromiseCallback<T> {
    @nativeInvoke
    operator fun invoke(value: T? = definedExternally, vararg args: Any)
}
I need an instance of this as a function parameter, I tried creating one like this:
Copy code
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 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?
g
Not sure if I'm interpreting what you need correctly, but a type alias might be what you need
Copy code
typealias JQueryPromiseCallback<T> = (T?, dynamic) -> dynamic
b
@zsmb: @gbaldeck is right — best way 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.
z
Thanks, I ended up writing my own function instead of the generated one that I was trying to call, and made it take a functional type instead of an interface. It works perfectly.
I suppose it would be worth writing a jQuery header manually that takes nicer types than the generated one. I don't know if this exists already, but I didn't manage to find one. I might just get on it myself.
I might just get on it myself.
You can do it base on converted code. Any way feel free to ask any question.
We going to create repository with such manually edited/written declarations, so, it could be your contribution to it 😉
z
That sounds great, is there a way to get notified? Should I just check on this channel to hear about it?
b
I’ve created the issue about it https://youtrack.jetbrains.com/issue/KT-19488
👍 1