nuxt-community / composition-api

Composition API hooks for Nuxt 2.
https://composition-api.nuxtjs.org
MIT License
706 stars 101 forks source link

docs: there some issue with vuex store doc #556

Open hotrungnhan opened 3 years ago

hotrungnhan commented 3 years ago

📚 Is your documentation request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I feel I should be able to [...] but I can't see how to do it from the docs. i find out a little issue with vuex store. "userStore" interface is so diferent with vuex interface "userStore" which is

/// from vuex
useStore<S = any>(injectKey?: InjectionKey<Store<S>> | string): Store<S>;
/// from composition-api
useStore<S = any>(injectKey?: InjectionKey<S> | string): Store<S>;

So there will caught you have to import like

export const key: InjectionKey<State> = Symbol()
//instead of 
import {Store} from 'vuex'
export const key: InjectionKey<Store<State>> = Symbol()

what ever it a feature or a bug , you might need to update new document for this 🔍 Where should you find it? What page of the docs do you expect this information to be found on?

//https://composition-api.nuxtjs.org/packages/store/
import { defineComponent, useStore } from '@nuxtjs/composition-api'

export interface State {
  count: number
}

export const key: InjectionKey<Store<State>> = Symbol()

export default defineComponent({
  setup() {
    const store = useStore(key)
    const store = useStore<State>()
    // In both of these cases, store.state.count will be typed as a number
  },
})

ℹ️ Additional context Add any other context or information.

hotrungnhan commented 3 years ago

i cant use vuex with typescript now , could you guy make a little example ?

danielroe commented 3 years ago

@hotrungnhan Could you explain what you have tried and what isn't working for you? Ideally via a reproduction (https://template.nuxtjs.org).

hotrungnhan commented 3 years ago

https://codesandbox.io/s/eloquent-mccarthy-jv6n9?file=/pages/index.vue i write it on typescipt. just edit ~/store/index and pages/index.vue file