Client - extend store typing in components

This commit is contained in:
Sam
2021-08-11 22:12:02 +02:00
parent a20a646687
commit 72db7afe44
10 changed files with 93 additions and 15 deletions

View File

@ -1,5 +1,6 @@
export enum RootGetters {
ERROR_MESSAGE = 'ERROR_MESSAGE',
LANGUAGE = 'LANGUAGE',
}
export enum RootMutations {

View File

@ -6,4 +6,7 @@ export const getters: GetterTree<IRootState, IRootState> & IRootGetters = {
[ROOT_STORE.GETTERS.ERROR_MESSAGE]: (state: IRootState) => {
return state.errorMessage
},
[ROOT_STORE.GETTERS.LANGUAGE]: (state: IRootState) => {
return state.language
},
}

View File

@ -8,4 +8,5 @@ export interface IRootState {
export interface IRootGetters {
[ROOT_STORE.GETTERS.ERROR_MESSAGE](state: IRootState): string | null
[ROOT_STORE.GETTERS.LANGUAGE](state: IRootState): string
}

View File

@ -1,8 +1,28 @@
import { Store as VuexStore, CommitOptions } from 'vuex'
import { ROOT_STORE } from '@/store/constants'
import { IRootState } from '@/store/modules/root/interfaces'
import { IRootGetters, IRootState } from '@/store/modules/root/interfaces'
export type TRootMutations<S = IRootState> = {
[ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGE](state: S): void
[ROOT_STORE.MUTATIONS.SET_ERROR_MESSAGE](state: S, errorMessage: string): void
[ROOT_STORE.MUTATIONS.UPDATE_LANG](state: S, language: string): void
}
export type TRootStoreModule<S = IRootState> = Omit<
VuexStore<S>,
'commit' | 'getters' | 'dispatch'
> & {
getters: {
[K in keyof IRootGetters]: ReturnType<IRootGetters[K]>
}
} & {
commit<
K extends keyof TRootMutations,
P extends Parameters<TRootMutations[K]>[1]
>(
key: K,
payload?: P,
options?: CommitOptions
): ReturnType<TRootMutations[K]>
}