Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No $store in components #526

Open
xornet-sl opened this issue Nov 15, 2021 · 1 comment
Open

No $store in components #526

xornet-sl opened this issue Nov 15, 2021 · 1 comment

Comments

@xornet-sl
Copy link

xornet-sl commented Nov 15, 2021

I'm using version 1.0.0 with vue 3 and vuex 4. TS 4.1.6
When I'm direct-importing created store and trying to use it just like in documentation - everything is totally fine. But I want to register it in all components and use my store in methods using this.$store. When I try to do that I don't see any $store registered (but store was used by createApp().use(store) in index.ts). I don't know why but this code from global.d.ts doesn't work automatically:

declare module "@vue/runtime-core" {
  interface ComponentCustomProperties {
    $store: Store<unknown>;
  }
}

And even if I add this code manually in my store's index.ts, I don't get any typing in this.$store just because $store is Store<unknown>

image

createComposable works just fine but I don't like to use setup() everywhere...

@vdkrasny
Copy link
Contributor

This library does not provide typing of the global $store option.
In order to get your module with all types you either have to use Component Mapper or Composable Function or context

import Vue from 'vue'
import { foo } from '@/store/modules/foo'

export default Vue.extend({
  mounted() {
    const typedFooModule = foo.context(this.$store)

    // Call `increment` action
    typedFooModule.actions.increment(1)
  }
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants