1 | import { ComponentPublicInstance } from 'vue';
|
2 | import { Dispatch, Commit } from './index';
|
3 |
|
4 | type Computed = () => any;
|
5 | type InlineComputed<T extends Function> = T extends (...args: any[]) => infer R ? () => R : never
|
6 | type MutationMethod = (...args: any[]) => void;
|
7 | type ActionMethod = (...args: any[]) => Promise<any>;
|
8 | type InlineMethod<T extends (fn: any, ...args: any[]) => any> = T extends (fn: any, ...args: infer Args) => infer R ? (...args: Args) => R : never
|
9 | type CustomVue = ComponentPublicInstance & Record<string, any>;
|
10 |
|
11 | interface Mapper<R> {
|
12 | <Key extends string>(map: Key[]): { [K in Key]: R };
|
13 | <Map extends Record<string, string>>(map: Map): { [K in keyof Map]: R };
|
14 | }
|
15 |
|
16 | interface MapperWithNamespace<R> {
|
17 | <Key extends string>(namespace: string, map: Key[]): { [K in Key]: R };
|
18 | <Map extends Record<string, string>>(namespace: string, map: Map): { [K in keyof Map]: R };
|
19 | }
|
20 |
|
21 | interface MapperForState {
|
22 | <S, Map extends Record<string, (this: CustomVue, state: S, getters: any) => any> = {}>(
|
23 | map: Map
|
24 | ): { [K in keyof Map]: InlineComputed<Map[K]> };
|
25 | }
|
26 |
|
27 | interface MapperForStateWithNamespace {
|
28 | <S, Map extends Record<string, (this: CustomVue, state: S, getters: any) => any> = {}>(
|
29 | namespace: string,
|
30 | map: Map
|
31 | ): { [K in keyof Map]: InlineComputed<Map[K]> };
|
32 | }
|
33 |
|
34 | interface MapperForAction {
|
35 | <Map extends Record<string, (this: CustomVue, dispatch: Dispatch, ...args: any[]) => any>>(
|
36 | map: Map
|
37 | ): { [K in keyof Map]: InlineMethod<Map[K]> };
|
38 | }
|
39 |
|
40 | interface MapperForActionWithNamespace {
|
41 | <Map extends Record<string, (this: CustomVue, dispatch: Dispatch, ...args: any[]) => any>>(
|
42 | namespace: string,
|
43 | map: Map
|
44 | ): { [K in keyof Map]: InlineMethod<Map[K]> };
|
45 | }
|
46 |
|
47 | interface MapperForMutation {
|
48 | <Map extends Record<string, (this: CustomVue, commit: Commit, ...args: any[]) => any>>(
|
49 | map: Map
|
50 | ): { [K in keyof Map]: InlineMethod<Map[K]> };
|
51 | }
|
52 |
|
53 | interface MapperForMutationWithNamespace {
|
54 | <Map extends Record<string, (this: CustomVue, commit: Commit, ...args: any[]) => any>>(
|
55 | namespace: string,
|
56 | map: Map
|
57 | ): { [K in keyof Map]: InlineMethod<Map[K]> };
|
58 | }
|
59 |
|
60 |
|
61 | interface NamespacedMappers {
|
62 | mapState: Mapper<Computed> & MapperForState;
|
63 | mapMutations: Mapper<MutationMethod> & MapperForMutation;
|
64 | mapGetters: Mapper<Computed>;
|
65 | mapActions: Mapper<ActionMethod> & MapperForAction;
|
66 | }
|
67 |
|
68 | export declare const mapState: Mapper<Computed>
|
69 | & MapperWithNamespace<Computed>
|
70 | & MapperForState
|
71 | & MapperForStateWithNamespace;
|
72 |
|
73 | export declare const mapMutations: Mapper<MutationMethod>
|
74 | & MapperWithNamespace<MutationMethod>
|
75 | & MapperForMutation
|
76 | & MapperForMutationWithNamespace;
|
77 |
|
78 | export declare const mapGetters: Mapper<Computed>
|
79 | & MapperWithNamespace<Computed>;
|
80 |
|
81 | export declare const mapActions: Mapper<ActionMethod>
|
82 | & MapperWithNamespace<ActionMethod>
|
83 | & MapperForAction
|
84 | & MapperForActionWithNamespace;
|
85 |
|
86 | export declare function createNamespacedHelpers(namespace: string): NamespacedMappers;
|