External overloaded operators

#1

In Axios an instance can be created, and other than calling methods you can invoke it directly.
Naturally I would add something like “operator fun invoke(config: AxiosConfigSettings): AxiosPromise” to my external interface AxiosInstance.

However, at runtime I get “Uncaught TypeError: $module$axios.invoke is not a function”.

How can this be accomplished?

#2
operator fun AxiosInstance.invoke(config: AxiosConfigSettings): AxiosPromise

Or am I missing something?

#3

Writing it like that a body is required and interfaces don’t allow that.

For now I have to assume that operator overloading doesn’t work for externals in kotlin/js.

#4
interface A
class B : A
operator fun A.invoke() {
    println("hi2")
} 
fun main() {
   val b = B()
    b()
}

This works…
Or is external not from outside the interface?

#5

I’m sorry, but I don’t think you know what I mean by external: https://kotlinlang.org/docs/reference/js-interop.html

Also, I don’t want to make my own invoke function. I want to be able to call the invoke function on the object in javascript. That is why I’m defining an external.

So in the javascript module Axios you have an object called axios. You can call methods on it like axios.get() and axios.post(). But you can also use it as a function axios(). I want to call THAT function.

The natural solution would be to define an invoke operator like I would for get and post. But as I said that doesn’t work when I in runtime get “Uncaught TypeError: $module$axios.invoke is not a functio”.
Remember when you define external methods you are not implementing it. You are only telling the kotlin compiler what is in the javascript module.