diff --git a/types/helpers.d.ts b/types/helpers.d.ts index c7530151d..1b80ff05c 100644 --- a/types/helpers.d.ts +++ b/types/helpers.d.ts @@ -6,39 +6,45 @@ type Computed = () => any; type MutationMethod = (...args: any[]) => void; type ActionMethod = (...args: any[]) => Promise; type CustomVue = Vue & Dictionary +type TypedDictionary = { [key in K]: V } +type CompleteObject = { [key: string]: string }; interface Mapper { - (map: string[]): Dictionary; - (map: Dictionary): Dictionary; + (map: K[]): TypedDictionary; + (map: { [key in K]: string }): TypedDictionary; } interface MapperWithNamespace { - (namespace: string, map: string[]): Dictionary; - (namespace: string, map: Dictionary): Dictionary; + (namespace: string, map: K[]): TypedDictionary; + (namespace: string, map: { [key in K]: string }): TypedDictionary; } +type MappingFunction = (this: CustomVue, fn: F, ...args: any[]) => any + interface FunctionMapper { - (map: Dictionary<(this: CustomVue, fn: F, ...args: any[]) => any>): Dictionary; + (map: { [key in K]: MappingFunction }): TypedDictionary; } interface FunctionMapperWithNamespace { - ( + ( namespace: string, - map: Dictionary<(this: CustomVue, fn: F, ...args: any[]) => any> - ): Dictionary; + map: { [key in K]: MappingFunction } + ): TypedDictionary; } +type StateMappingFunction = (this: CustomVue, state: S, getters: any) => any + interface MapperForState { - ( - map: Dictionary<(this: CustomVue, state: S, getters: any) => any> - ): Dictionary; + ( + map: { [key in K]: StateMappingFunction } + ): TypedDictionary; } interface MapperForStateWithNamespace { - ( + ( namespace: string, - map: Dictionary<(this: CustomVue, state: S, getters: any) => any> - ): Dictionary; + map: { [key in K]: StateMappingFunction } + ): TypedDictionary; } interface NamespacedMappers { diff --git a/types/test/helpers.ts b/types/test/helpers.ts index 569a9ecaf..3bbefaeb7 100644 --- a/types/test/helpers.ts +++ b/types/test/helpers.ts @@ -5,7 +5,9 @@ import { mapGetters, mapActions, mapMutations, - createNamespacedHelpers + createNamespacedHelpers, + Commit, + Dispatch } from "../index"; const helpers = createNamespacedHelpers('foo'); @@ -65,7 +67,7 @@ new Vue({ h: "h" }), mapActions({ - g (dispatch, a: string, b: number, c: boolean): void { + g (dispatch: Dispatch, a: string, b: number, c: boolean): void { dispatch('g', { a, b, c }) dispatch({ type: 'g', @@ -80,7 +82,7 @@ new Vue({ h: "h" }), mapActions('foo', { - g (dispatch, a: string, b: number, c: boolean): void { + g (dispatch: Dispatch, a: string, b: number, c: boolean): void { dispatch('g', { a, b, c }) dispatch({ type: 'g', @@ -96,7 +98,7 @@ new Vue({ j: "j" }), mapMutations({ - i (commit, a: string, b: number, c: boolean): void { + i (commit: Commit, a: string, b: number, c: boolean): void { commit('i', { a, b, c }) commit({ type: 'i', @@ -111,7 +113,7 @@ new Vue({ j: "j" }), mapMutations('foo', { - i (commit, a: string, b: number, c: boolean): void { + i (commit: Commit, a: string, b: number, c: boolean): void { commit('i', { a, b, c }) commit({ type: 'i', @@ -127,7 +129,7 @@ new Vue({ m: "m" }), helpers.mapActions({ - m (dispatch, value: string) { + m (dispatch: Dispatch, value: string) { dispatch('m', value) } }), @@ -137,13 +139,35 @@ new Vue({ n: "n" }), helpers.mapMutations({ - n (commit, value: string) { + n (commit: Commit, value: string) { commit('m', value) } }), + helpers.mapMutations({ + n: "n", + m: "m" + }), { otherMethod () {} } ) }); + +const actions = mapActions({ + mAlias: "m" +}) + +actions.mAlias() + +const actionsNamespaced = mapActions('namespace', { + mAlias: "m" +}) + +actionsNamespaced.mAlias() + +const actionsNamespaced2 = helpers.mapActions({ + mAlias: "m" +}) + +actionsNamespaced2.mAlias()