Skip to content

Commit

Permalink
fix: fix #1032, relax vue typing in helpers (#1044)
Browse files Browse the repository at this point in the history
  • Loading branch information
HerringtonDarkholme authored and ktsn committed Jan 3, 2018
1 parent ca64c3f commit 7c7ed1d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 5 additions & 4 deletions types/helpers.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type Dictionary<T> = { [key: string]: T };
type Computed = () => any;
type MutationMethod = (...args: any[]) => void;
type ActionMethod = (...args: any[]) => Promise<any>;
type CustomVue = Vue & Dictionary<any>

interface Mapper<R> {
(map: string[]): Dictionary<R>;
Expand All @@ -17,26 +18,26 @@ interface MapperWithNamespace<R> {
}

interface FunctionMapper<F, R> {
(map: Dictionary<(this: typeof Vue, fn: F, ...args: any[]) => any>): Dictionary<R>;
(map: Dictionary<(this: CustomVue, fn: F, ...args: any[]) => any>): Dictionary<R>;
}

interface FunctionMapperWithNamespace<F, R> {
(
namespace: string,
map: Dictionary<(this: typeof Vue, fn: F, ...args: any[]) => any>
map: Dictionary<(this: CustomVue, fn: F, ...args: any[]) => any>
): Dictionary<R>;
}

interface MapperForState {
<S>(
map: Dictionary<(this: typeof Vue, state: S, getters: any) => any>
map: Dictionary<(this: CustomVue, state: S, getters: any) => any>
): Dictionary<Computed>;
}

interface MapperForStateWithNamespace {
<S>(
namespace: string,
map: Dictionary<(this: typeof Vue, state: S, getters: any) => any>
map: Dictionary<(this: CustomVue, state: S, getters: any) => any>
): Dictionary<Computed>;
}

Expand Down
5 changes: 4 additions & 1 deletion types/test/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ new Vue({
k: "k"
}),
helpers.mapState({
k: (state: any, getters: any) => state.k + getters.k
k: (state: any, getters: any) => state.k + getters.k,
useThis(state: any, getters: any) {
return state.k + getters.k + this.whatever
}
}),

helpers.mapGetters(["l"]),
Expand Down

0 comments on commit 7c7ed1d

Please sign in to comment.