4

I am playing with Vue and KotlinJS and thought that I can simply get access to the Vue observer functions like Vue.set this way:

@JsModule("vue")
@JsName("Vue")
open external class Vue {
    companion object {
        fun <T> set(target: Any, key: String, value: T): T
        fun <T> set(target: Array<T>, key: Int, value: T): T
    }
}
...
Vue.set(state.todos, 1, todo)

However I get

Uncaught TypeError: $module$vue.set is not a function

where $module$vue = require("vue").

What is working though is this (notice the object default instead of companion object:

@JsModule("vue")
@JsName("Vue")
open external class Vue {
    object default {
        fun <T> set(target: Any, key: String, value: T): T
        fun <T> set(target: Array<T>, key: Int, value: T): T
    }
}
...
Vue.default.set(state.todos, 1, todo)

Why is that and is there a good way to get around this?

n_l
  • 844
  • 1
  • 6
  • 19

1 Answers1

1

Instead of @JsName("Vue"), try: @JsName("default")

AlexO
  • 1,311
  • 12
  • 18