how to set up vuex with typescript

The solution for “how to set up vuex with typescript” can be found here. The following code will assist you in solving the problem.

// store.ts
import { InjectionKey } from ‘vue’
import { createStore, Store } from ‘vuex’

// define your typings for the store state
export interface State {
count: number

// define injection key
export const key: InjectionKey> = Symbol()

export const store = createStore({
state: {
count: 0

// define your own `useStore` composition function
export function useStore () {
return baseUseStore(key)

// main.ts
import { createApp } from ‘vue’
import { store, key } from ‘./store’

const app = createApp({ … })

// pass the injection key
app.use(store, key)


Thank you for using DeclareCode; We hope you were able to resolve the issue.

More questions on [categories-list]

inline scripts encapsulated in