Client - extend store typing in components
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
export enum RootGetters {
|
||||
ERROR_MESSAGE = 'ERROR_MESSAGE',
|
||||
LANGUAGE = 'LANGUAGE',
|
||||
}
|
||||
|
||||
export enum RootMutations {
|
||||
|
@ -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
|
||||
},
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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]>
|
||||
}
|
||||
|
@ -1,6 +1,36 @@
|
||||
import { Store as VuexStore, CommitOptions, DispatchOptions } from 'vuex'
|
||||
|
||||
import { USER_STORE } from '@/store/constants'
|
||||
import { IUserState } from '@/store/modules/user/interfaces'
|
||||
import {
|
||||
IUserActions,
|
||||
IUserGetters,
|
||||
IUserState,
|
||||
} from '@/store/modules/user/interfaces'
|
||||
|
||||
export type TUserMutations<S = IUserState> = {
|
||||
[USER_STORE.MUTATIONS.UPDATE_AUTH_TOKEN](state: S, authToken: string): void
|
||||
}
|
||||
|
||||
export type TUserStoreModule<S = IUserState> = Omit<
|
||||
VuexStore<S>,
|
||||
'commit' | 'getters' | 'dispatch'
|
||||
> & {
|
||||
dispatch<K extends keyof IUserActions>(
|
||||
key: K,
|
||||
payload?: Parameters<IUserActions[K]>[1],
|
||||
options?: DispatchOptions
|
||||
): ReturnType<IUserActions[K]>
|
||||
} & {
|
||||
getters: {
|
||||
[K in keyof IUserGetters]: ReturnType<IUserGetters[K]>
|
||||
}
|
||||
} & {
|
||||
commit<
|
||||
K extends keyof TUserMutations,
|
||||
P extends Parameters<TUserMutations[K]>[1]
|
||||
>(
|
||||
key: K,
|
||||
payload?: P,
|
||||
options?: CommitOptions
|
||||
): ReturnType<TUserMutations[K]>
|
||||
}
|
||||
|
10
fittrackee_client/src/store/types.ts
Normal file
10
fittrackee_client/src/store/types.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { TRootStoreModule } from '@/store/modules/root/types'
|
||||
import { TUserStoreModule } from '@/store/modules/user/types'
|
||||
|
||||
type StoreModules = {
|
||||
rootModule: TRootStoreModule
|
||||
userModule: TUserStoreModule
|
||||
}
|
||||
|
||||
export type Store = TUserStoreModule<Pick<StoreModules, 'userModule'>> &
|
||||
TRootStoreModule<Pick<StoreModules, 'rootModule'>>
|
Reference in New Issue
Block a user