Using Vuex in Typescript

vuex uses module, and then wants to use store.state.a to report type errors in the TS file

// store/index.ts

// ...
Vue.use(Vuex);

const store: StoreOptions<RootState> = {
    modules: {
        a
    }
};

export default new Vuex.Store<RootState>(store);
// a.ts
// ...
export const state: State = {
    id: 1
};

const namespaced: boolean = true;

export const user: Module<UserState, RootState> = {
    namespaced,
    state
};
// use.ts
// TSVue
store.state.a.id // [ts] "{}" "a"  [2339]

how should I correct this so that this exception is not thrown?
Thank you!

Jun.06,2022

uses Getters, refer to ide-router-ts" rel=" nofollow noreferrer "> https://stackoverflow.com/que...


write in the original vue way is easy to cause type loss, it is recommended to use a vuex ts package to write, my current project is using: vuex-module-decorators , or very easy to use!


define RootState

//storeModel.ts
export interface RootState {
    a:{
        id: string
    }
}

and then introduce

into use.ts
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e4c0b2-44e7a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e4c0b2-44e7a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?