I'm working in typescripting my vue directive, but I just cannot seem to find what types should i use for Vue install function.
Going with install(Vue: any): void
seems a little bit odd.
Ive tried importing Vue and then using install(Vue: Vue)
, but that throws out an error that there is no .directive
on Vue, which is also odd.
How should I type install function? Does Vue
type suppose to work here? What am I missing here, or does Vue
misses something?
import { DirectiveOptions } from "vue"
const directive: DirectiveOptions = {
bind(elem, bind, vn) {
console.log('bound')
}
};
export default {
install(Vue: any): void { // what types should be used here?
Vue.directive("do-stuff", directive);
}
};
The type you want is VueConstructor
. Here's how a Typescript Vue plugin should be authored
import { VueConstructor, PluginObject, DirectiveOptions } from "vue"
const directive: DirectiveOptions = {
bind(elem, bind, vn) {
console.log('bound')
}
}
const plugin: PluginObject<any> = {
install (Vue: VueConstructor): void {
Vue.directive("do-stuff", directive)
}
}
export default plugin
See https://github.com/vuejs/vue/blob/dev/types/vue.d.ts#L80
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With