vuejs / vue-class-component

ES / TypeScript decorator for class-style Vue components.
MIT License
5.81k stars 429 forks source link

Augumenting types does not work with `vue-class-component` #574

Open tbitowt opened 2 years ago

tbitowt commented 2 years ago

Looking at Vue.js guide for augumenting types (https://v3.vuejs.org/guide/typescript-support.html#augmenting-types-for-globalproperties) I tried to add my own $store property to my Vue components typings.

Unfortunately this does not work at all. Intellisense does note recognize $store property.

Here is what I tried:

declare module "@vue/runtime-core" {
  // declare your own store states
  interface State {
    count: number;
  }

  // provide typings for `this.$store`
  interface ComponentCustomProperties {
    $store: Store<State>;
  }
}

I managed to make a workaround for that (which also does not work as expected, but at least somehow). I added following to a global d.ts file:


declare module "vue-class-component" {
  interface Vue {
    $store: Store<State>;
  }
}```

The problem with that is, that intellisense does not recognize `$store` property, but after I type it manually it manages to show all `Store` properties and methods.