import { ActionContext, Store } from "vuex" import { ActionsImpl, GettersImpl, ModuleOptions, ModulesImpl, MutationsImpl, StoreOptions, StoreOrModuleOptions } from "./index" export interface CreatedStore { store: ToDirectStore rootGetterContext(args: [any, any]): DirectGetterContext moduleGetterContext( args: [any, any, any, any], module: O ): DirectGetterContext rootActionContext(originalContext: ActionContext): DirectActionContext moduleActionContext( originalContext: ActionContext, module: O ): DirectActionContext } export type ToDirectStore = ShowContent<{ readonly state: ShowContent> getters: ShowContent> commit: ShowContent> dispatch: ShowContent> original: VuexStore }> export type VuexStore = Store>> & { direct: ToDirectStore } // State type DirectState = ToStateObj & GetStateInModules> type GetStateInModules = { readonly [M in keyof I]: DirectState } type ToStateObj = T extends (() => any) ? Readonly> : Readonly // Getters // export type SelfGetters = ToDirectGetters> type DirectGetters = ToDirectGetters> & GetGettersInModules>> & MergeGettersFromModules>> type GetGettersInModules = { readonly [M in keyof I]: DirectGetters } type ToDirectGetters = { readonly [K in keyof T]: ReadonlyReturnTypeExceptCb } type ReadonlyReturnTypeExceptCb any> = T extends ((...args1: any) => (...args2: any) => any) ? ReturnType : Readonly> type MergeGettersFromModules = UnionToIntersection>> // Mutations type DirectMutations = ToDirectMutations> & GetMutationsInModules>> & MergeMutationsFromModules>> type GetMutationsInModules = { [M in keyof I]: DirectMutations } type ToDirectMutations = { [K in keyof T]: Parameters[1] extends undefined ? (() => void) : (Extract[1], undefined> extends never ? ((payload: Parameters[1]) => void) : ((payload?: Parameters[1]) => void)) } type MergeMutationsFromModules = UnionToIntersection>> // Actions type DirectActions = ToDirectActions> & GetActionsInModules>> & MergeActionsFromModules>> type GetActionsInModules = { [M in keyof I]: DirectActions } type ToDirectActions = { [K in keyof T]: Parameters[1] extends undefined ? (() => PromiseOf>) : (Extract[1], undefined> extends never ? ((payload: Parameters[1]) => PromiseOf>) : ((payload?: Parameters[1]) => PromiseOf>)) } type MergeActionsFromModules = UnionToIntersection>> // ActionContext export type DirectActionContext = ShowContent<{ rootState: DirectState rootGetters: DirectGetters rootCommit: DirectMutations rootDispatch: DirectActions state: DirectState getters: DirectGetters commit: DirectMutations dispatch: DirectActions }> export type DirectGetterContext = ShowContent<{ rootState: DirectState rootGetters: DirectGetters state: DirectState getters: DirectGetters }> // Common helpers type PromiseOf = T extends Promise ? T : Promise type FilterNamespaced = Pick> type KeyOfType = { [P in keyof T]: T[P] extends U ? P : never }[keyof T] type FilterNotNamespaced = Pick> type NotKeyOfType = { [P in keyof T]: T[P] extends U ? never : P }[keyof T] type OrEmpty = T extends {} ? T : {} type UnionToIntersection = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never type ShowContent = T extends Function ? T : T extends object ? T extends infer O ? { [K in keyof O]: ShowContentDepth1 } : never : T type ShowContentDepth1 = T extends Function ? T : T extends object ? T extends infer O ? { [K in keyof O]: O[K] } : never : T