Are there types for Vue `install` function? Should property `directive` exist on type `Vue`?

800 Views Asked by At

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);
  }
};
1

There are 1 best solutions below

0
On BEST ANSWER

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