paroi-tech / direct-vuex

Use and implement your Vuex store with TypeScript types. Compatible with the Vue 3 composition API.
Creative Commons Zero v1.0 Universal
258 stars 14 forks source link

Usage with Vue 3? #62

Closed szyszak closed 3 years ago

szyszak commented 3 years ago

Hi, I'm trying to use this plugin with Vue 3, Vuex 4 and TypeScript. The docs show how to use direct-vuex using Vue 2 plugin system, but new Vue({store: store.original}).$mount("#app") doesn't work in Vue 3. I use createApp(App).use({ store: store.original }).mount('#app');, but then I get this error:

Argument of type '{ store: { readonly state: {}; readonly getters: any; install: (app: App, injectKey?: string | InjectionKey<Store> | undefined) => void; replaceState: (state: {}) => void; ... 9 more ...; direct: { ...; }; }; }' is not assignable to parameter of type 'Plugin_2'. Object literal may only specify known properties, and 'store' does not exist in type 'Plugin_2'.

Does it mean that this plugin is not compatible with Vue 3? I assumed it is, because the docs say it's compatible with Vue 3 composition API.

davidmatter commented 3 years ago

Would love to see Vue 3/Vuex 4 support too  ☺️

mspoulsen commented 3 years ago

Is there a need for direct-veux with vue3/vuex4? 😳

I have not had the chance to try vuex4 yet but my understanding was that it came with TS support?

davidmatter commented 3 years ago

Vuex 4 only provides typed state. The beauty of direct-vuex lies in the fully typed actions/mutations surface. You can reach a similar degree of typing doing something like this. For my taste there is too much boilerplate code involved in the linked solution, though. @paleo That's why I love direct-vuex.

OmgImAlexis commented 3 years ago

Here's an open PR that supports Vue3 and vuex@next

https://github.com/paroi-tech/direct-vuex/pull/63

paleo commented 3 years ago

@OmgImAlexis Thank you. It's merged.

Please install with:

npm i direct-vuex@next
davidmatter commented 3 years ago

@OmgImAlexis @paleo thank you very much! 🙏

szyszak commented 3 years ago

Haven't tested it myself, but I assume that this issue has been resolved by @OmgImAlexis and I'm closing it.