import _Vue, { WatchOptions } from 'vue'; import './vue'; /** * When and if https://github.com/Microsoft/TypeScript/issues/12754 is * implemented, we can support namespaced modules - and Vuex can be completely * typesafe! * * We also need Flatten to be infinitely deep since unnamespaced sub modules * can have getters, mutations, and actions merged down into the store. * I was calling Flatten multiple times but that results in TypeScript dying. * * TODO * - Namespace support, obviously. Requires TS improvements. * - Root store $store has proper types. Requires TS improvements. * - Nested module merging. Requires TS improvements. * - Namespaced actions marked with root=true need to be placed in root store. */ export declare function install(Vue: typeof _Vue): void; export type CustomVue = _Vue & { [key: string]: any }; export type EmptyObject = { [key: string]: never }; export type OptionalProperties = T extends EmptyObject ? {} : R; export type IfEquals = (() => T extends X ? 1 : 2) extends (() => T extends Y ? 1 : 2) ? A : B; export type IsNever = [X] extends [never] ? T : F; export type ObjKeyof = T extends object ? keyof T : never; export type KeyofKeyof = ObjKeyof | { [K in keyof T]: ObjKeyof }[keyof T]; export type StripNever = Pick }[keyof T]>; export type Lookup = T extends any ? K extends keyof T ? T[K] : never : never; export type Flatten = T extends object ? StripNever<{ [K in KeyofKeyof]: Exclude | { [P in keyof T]: Lookup }[keyof T] }> : T export type Intersect = T extends object ? { [K in keyof T]: (arg: T[K]) => void } extends Record< keyof T, (arg: infer A) => void > ? A : never : T; export type Resolvable = T | (() => T); export type GetSingleElement = A extends [] ? N : A extends [infer P] ? P : A extends [(infer P)?] ? P | undefined : N; export type Mutation = (payload: P) => R; export type IsMutation = M extends Mutation ? (R extends void ? Y : N) : N; export type MutationPayload = F extends (...any: infer A) => void ? GetSingleElement : N; export type MutationPayloadRoot = { [K in keyof R]: K extends A ? MutationPayload : K extends 'modules' ? { [M in keyof R[K]]: { [E in keyof R[K][M]]: E extends A ? MutationPayload : never }[keyof R[K][M]] }[keyof R[K]] : never }[keyof R]; export type Action> = (payload: P) => I; export type IsAction = A extends Action ? (I extends Promise ? Y : N) : N; export type ActionPayload = F extends (...args: infer A) => Promise ? GetSingleElement : N; export type ActionPayloadRoot = { [K in keyof R]: K extends A ? ActionPayload : K extends 'modules' ? { [M in keyof R[K]]: { [E in keyof R[K][M]]: E extends A ? ActionPayload : never }[keyof R[K][M]] }[keyof R[K]] : never }[keyof R]; export type ActionResult = A extends Action ? R : never; export type ActionResultRoot = { [K in keyof R]: K extends A ? ActionResult : K extends 'modules' ? { [M in keyof R[K]]: { [E in keyof R[K][M]]: E extends A ? ActionResult : never }[keyof R[K][M]] }[keyof R[K]] : never }[keyof R]; export type StateKeys = { [P in keyof T]-?: T[P] extends Function ? never : P extends 'modules' | 'namespaced' ? never : IfEquals<{ [Q in P]: T[P] }, { -readonly [Q in P]: T[P] }, P> }[keyof T]; export type GetterKeys = { [P in keyof T]-?: IfEquals<{ [Q in P]: T[P] }, { -readonly [Q in P]: T[P] }, never, P> }[keyof T]; export type MutationKeys = { [K in keyof S]: IsMutation }[keyof S]; export type MutationKeysWithPayload = { [K in keyof S]: IsMutation extends never ? never : K> }[keyof S]; export type MutationKeysNoPayload = { [K in keyof S]: IsMutation extends never ? K : never> }[keyof S]; export type MutationKeysRoot = MutationKeys | { [P in keyof R]: P extends 'modules' ? { [K in keyof R[P]]: MutationKeys }[keyof R[P]] : never; }[keyof R]; export type ActionKeys = { [K in keyof S]: IsAction }[keyof S]; export type ActionKeysWithPayload = { [K in keyof S]: IsAction extends never ? never : K> }[keyof S]; export type ActionKeysNoPayload = { [K in keyof S]: IsAction extends never ? K : never> }[keyof S]; export type ActionKeysRoot = ActionKeys | { [P in keyof R]: P extends 'modules' ? { [K in keyof R[P]]: ActionKeys }[keyof R[P]] : never; }[keyof R]; export type ModuleKeys = { [P in keyof T]: P extends 'modules' ? (T[P] extends object ? keyof T[P] : never ) : never }[keyof T]; export type MergedModuleKeys = { [P in keyof T]: P extends 'modules' ? (T[P] extends object ? { [M in keyof T[P]]: IsNamespacedModule extends never ? M : never}[keyof T[P]] : never ) : never }[keyof T]; export type NamespacedModuleKeys = { [P in keyof T]: P extends 'modules' ? (T[P] extends object ? { [M in keyof T[P]]: IsNamespacedModule extends never ? never : M}[keyof T[P]] : never ) : never }[keyof T]; export type GetModule> = T extends { modules: { [K in M]: infer E } } ? E : never; export type IsNamespacedModule = M extends object ? { [P in keyof M]: P extends 'namespaced' ? (M[P] extends true ? P : never) : never }[keyof M] : never; export type GetNamespacedFor = { [P in keyof M]: P extends 'namespaced' ? M[P] extends true ? { namespaced: true } : never : never; }; export type StateInputFor = { [K in StateKeys]: T[K]; }; export type StateInput = Resolvable>; export type MergedStateFor = { [M in ModuleKeys]: T extends { modules: { [P in M]: infer E } } ? StateFor : never; }; export type StateFor = StateInputFor & MergedStateFor; export type GetterInputFor = { [K in GetterKeys]: T[K]; }; export type MergedGettersFor = { [M in MergedModuleKeys]: T extends { modules: { [P in M]: infer E } } ? GettersFor : never; }; export type GettersFor = GetterInputFor & Flatten>; export type GetterTree = { [K in GetterKeys]: (state: StateFor, getters: GettersFor, rootState: StateFor, rootGetters: GettersFor) => T[K]; }; export type MutationHandler = IsNever) => void, (state: StateFor, payload: P) => void>; export type MutationTree = { [K in MutationKeys]: T[K] extends Mutation ? MutationHandler : never; }; export type ActionHandler = IsNever, injectee: ActionContext) => Promise, (this: Store, injectee: ActionContext, payload: P) => Promise>; export type ActionTree = { [K in ActionKeys]: T[K] extends Action ? ( ActionHandler | { root?: boolean; handler: ActionHandler } ) : never; }; export type StoreOptions = { plugins?: Plugin[]; strict?: boolean; devtools?: boolean; } & OptionalProperties, { modules: ModuleTree }> & OptionalProperties, { state: StateInput }> & OptionalProperties, { getters: GetterTree }> & OptionalProperties, { mutations: MutationTree }> & OptionalProperties, { actions: ActionTree }>; export declare class Store { constructor(options: StoreOptions); readonly state: StateFor; readonly getters: GettersFor; replaceState(state: StateFor): void; commit: Commit; dispatch: Dispatch; subscribe (subscriber: MutationSubscriber): () => void; subscribeAction (subscriber: ActionSubscriber | ActionSubscribersObject): () => void; watch (getter: (state: StateFor, getters: GettersFor) => W, cb: (value: W, oldValue: W) => void, options?: WatchOptions): () => void; registerModule (path: string, module: Module, options?: ModuleOptions): void; registerModule (path: string[], module: Module, options?: ModuleOptions): void; unregisterModule (path: string): void; unregisterModule (path: string[]): void; hotUpdate (update: HotUpdate): void; } export type HotUpdate = { modules?: Partial> } & OptionalProperties, { getters: Partial> }> & OptionalProperties, { mutations: Partial> }> & OptionalProperties, { actions: Partial> }>; export interface ActionContext { state: StateFor; getters: GettersFor; commit: Commit; dispatch: Dispatch; rootState: StateFor; rootGetters: GettersFor; } export type Plugin = (store: Store) => any; export type MergedCommitFor = { [M in MergedModuleKeys]: T extends { modules: { [P in M]: infer E } } ? Commit : never; }; export type CommitFor = { > (type: K): void; > (type: K, payload: MutationPayload): void; > (type: K, payload: MutationPayload, options: CommitOptionsThis): void; > (payloadWithType: { type: K, payload: MutationPayload }): void; > (payloadWithType: { type: K, payload: MutationPayload }, options: CommitOptionsThis): void; (type: MutationPath, payload?: P): void; (type: MutationPath, payload: P | undefined, options: CommitOptionsThis): void; (payloadWithType: { type: MutationPath, payload: P }): void; (payloadWithType: { type: MutationPath, payload: P }, options: CommitOptionsThis): void; }; export type MergedRootCommitFor = { [M in MergedModuleKeys]: R extends { modules: { [P in M]: infer E } } ? RootCommit : never; }; export type RootCommitFor = { > (type: K, payload: MutationPayloadRoot, options: CommitOptionsRoot): void; > (payloadWithType: { type: K, payload: MutationPayload }, options: CommitOptionsRoot): void; (type: MutationPath, payload: P | undefined, options: CommitOptionsRoot): void; (payloadWithType: { type: MutationPath, payload: P }, options: CommitOptionsRoot): void; }; export type RootCommit = RootCommitFor & Intersect>; export type Commit = CommitFor & Intersect> & RootCommit; export interface CommitOptionsThis { silent?: boolean; root?: false } export interface CommitOptionsRoot { silent?: boolean; root: true } export type MergedDispatchFor = { [M in MergedModuleKeys]: T extends { modules: { [P in M]: infer E } } ? Dispatch : never; }; export interface DispatchFor { > (type: K): Promise>; > (type: K, payload: ActionPayload): Promise>; > (type: K, payload: ActionPayload, options: DispatchOptionsThis): Promise>; > (type: K, payload: ActionPayloadRoot, options: DispatchOptionsRoot): Promise>; (type: ActionPath, payload?: P): Promise; (type: ActionPath, payload: P | undefined, options: DispatchOptionsThis): Promise; (payloadWithType: { type: ActionPath, payload: P }): Promise; (payloadWithType: { type: ActionPath, payload: P }, options: DispatchOptionsThis): Promise; } export type RootDispatchFor = { > (type: K, payload: ActionPayload | undefined, options: DispatchOptionsRoot): Promise>; > (payloadWithType: { type: K, payload: ActionPayload }, options: DispatchOptionsRoot): Promise>; (type: ActionPath, payload: P | undefined, options: DispatchOptionsRoot): Promise; (payloadWithType: { type: ActionPath, payload: P }, options: DispatchOptionsRoot): Promise; }; export type Dispatch = DispatchFor & Intersect> & RootDispatchFor; export interface DispatchOptionsThis { root?: false; } export interface DispatchOptionsRoot { root: true; } export type MutationSubscriber = > (mutation: { type: K, payload: MutationPayload }, state: StateFor) => void; export type ActionSubscriber = > (action: { type: K, payload: ActionPayload }, state: StateFor) => void; export interface ActionSubscribersObject { before?: ActionSubscriber; after?: ActionSubscriber; } export type Module = OptionalProperties, { modules: ModuleTree; }> & OptionalProperties, { state: StateInput }> & OptionalProperties, { getters: GetterTree }> & OptionalProperties, { mutations: MutationTree }> & OptionalProperties, { actions: ActionTree }> & OptionalProperties, { namespaced: true }>; export interface ModuleOptions { preserveState?: boolean; } export type ModuleTree = { [M in ModuleKeys]: T extends { modules: { [K in M]: infer E } } ? Module : never; } export function path(): Path; export class Path { module>(module: M): Path, S>; state>(name: K): { get(): StatePath }; getter>(name: K): { get(): GetterPath }; mutation>(name: K): { get(): MutationPath> }; action>(name: K): { get(): ActionPath, ActionResult> }; get(): ModulePath } export class StatePath { faux: string } export class GetterPath { faux: string } export class MutationPath { faux: string } export class ActionPath { faux: string } export class ModulePath { faux: string } export type StateGetter = (this: CustomVue, state: StateFor, getters: GettersFor) => R; export type MutationIn = (this: CustomVue, commit: Commit, ...args: A) => X; export type MutationOut = (...args: A) => X; export type ActionIn = (this: CustomVue, dispatch: Dispatch, ...args: A) => Promise; export type ActionOut = (...args: A) => Promise; export declare function createHelpers(): MappersWithNamespace; export declare function createNamespacedHelpers (namespace: ModulePath): Mappers; export interface Mappers { mapState: MapperForState mapGetters: MapperForGetters mapMutations: MapperForMutations mapActions: MapperForActions } export interface MapperForGetters { , U = { [P in K]: () => T[P] }>(keys: K[]): U; , M extends { [key: string]: K }>(map: M): { [P in keyof M]: () => M[P] extends K ? T[M[P]] : never }; } export interface MapperForState { , U = { [P in K]: () => T[P] }>(keys: K[]): U; , M extends { [key: string]: K | StateGetter }>(map: M): { [P in keyof M]: () => M[P] extends K ? T[M[P]] : ( M[P] extends StateGetter ? R : never ) } } export interface MapperForMutations { , U = { [P in K]: MutationPayload extends never ? () => void : (payload: MutationPayload) => void }>(keys: K[]): U; , M extends { [key: string]: K | MutationIn }>(map: M): { [P in keyof M]: M[P] extends keyof T ? MutationPayload extends never ? () => void : (payload: MutationPayload) => void : (M[P] extends MutationIn ? MutationOut : never) }; } export interface MapperForActions { , U = { [P in K]: ActionPayload extends never ? () => Promise> : (payload: ActionPayload) => Promise> }>(keys: K[]): U; , M extends { [key: string]: K | ActionIn }>(map: M): { [P in keyof M]: M[P] extends keyof T ? ActionPayload extends never ? () => Promise> : (payload: ActionPayload) => Promise> : (M[P] extends ActionIn ? ActionOut : never) }; } export interface MappersWithNamespace { mapState: MapperForState & MapperForStateWithNamespace mapGetters: MapperForGetters & MapperForGettersWithNamespace mapMutations: MapperForMutations & MapperForMutationsWithNamespace mapActions: MapperForActions & MapperForActionsWithNamespace } export interface MapperForGettersWithNamespace { , U = { [P in K]: () => M[P] }>(namespace: ModulePath, keys: K[]): U; , N extends { [key: string]: K }>(namespace: ModulePath, map: N): { [P in keyof N]: () => N[P] extends K ? M[N[P]] : never }; } export interface MapperForStateWithNamespace { , U = { [P in K]: () => M[P] }>(namespace: ModulePath, keys: K[]): U; , N extends { [key: string]: K | StateGetter }>(namespace: ModulePath, map: N): { [P in keyof N]: () => N[P] extends K ? M[N[P]] : ( N[P] extends StateGetter ? R : never ) } } export interface MapperForMutationsWithNamespace { , U = { [P in K]: (payload: MutationPayload) => void }>(namespace: string, keys: K[]): U; , M extends { [key: string]: K | MutationIn }>(namespace: string, map: M): { [P in keyof M]: M[P] extends keyof T ? MutationPayload extends never ? () => void : (payload: MutationPayload) => void : (M[P] extends MutationIn ? MutationOut : never) }; } export interface MapperForActionsWithNamespace { , U = { [P in K]: (payload: ActionPayload) => Promise> }>(namespace: string, keys: K[]): U; , M extends { [key: string]: K | ActionIn }>(namespace: string, map: M): { [P in keyof M]: M[P] extends keyof T ? ActionPayload extends never ? () => Promise> : (payload: ActionPayload) => Promise> : (M[P] extends ActionIn ? ActionOut : never) }; } export const mapState: MapperForState & MapperForStateWithNamespace; export const mapGetters: MapperForGetters & MapperForGettersWithNamespace; export const mapMutations: MapperForMutations & MapperForMutationsWithNamespace; export const mapActions: MapperForActions & MapperForActionsWithNamespace; declare const _default: { Store: typeof Store, install: typeof install, mapState: typeof mapState, mapGetters: typeof mapGetters, mapMutations: typeof mapMutations, mapActions: typeof mapActions, createHelpers: typeof createHelpers, createNamespacedHelpers: typeof createNamespacedHelpers }; export default _default;