Skip to content

Commit 9196bb0

Browse files
dkulykposva
authored andcommitted
types: add component type to in-component guards (#2382)
Added support for resolving vm in the next((vm)=>{}) call. ``` @component<Test>({ beforeRouteEnter(to, from, next) { next((vm) => { vm.testBool = true; //TypeScript resolved this field. }); }, }) export default class Test extends Vue { public testBool: boolean = false; } ``` ![image](https://user-images.githubusercontent.com/370042/45268762-6521ca80-b48a-11e8-988a-d4abcf4b4eef.png)
1 parent 99c4436 commit 9196bb0

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

Diff for: types/router.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ type Dictionary<T> = { [key: string]: T };
66
export type RouterMode = "hash" | "history" | "abstract";
77
export type RawLocation = string | Location;
88
export type RedirectOption = RawLocation | ((to: Route) => RawLocation);
9-
export type NavigationGuard = (
9+
export type NavigationGuard<V extends Vue = Vue> = (
1010
to: Route,
1111
from: Route,
12-
next: (to?: RawLocation | false | ((vm: Vue) => any) | void) => void
12+
next: (to?: RawLocation | false | ((vm: V) => any) | void) => void
1313
) => any
1414

1515
export declare class VueRouter {

Diff for: types/vue.d.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ declare module "vue/types/vue" {
1515
declare module "vue/types/options" {
1616
interface ComponentOptions<V extends Vue> {
1717
router?: VueRouter;
18-
beforeRouteEnter?: NavigationGuard;
19-
beforeRouteLeave?: NavigationGuard;
20-
beforeRouteUpdate?: NavigationGuard;
18+
beforeRouteEnter?: NavigationGuard<V>;
19+
beforeRouteLeave?: NavigationGuard<V>;
20+
beforeRouteUpdate?: NavigationGuard<V>;
2121
}
2222
}

0 commit comments

Comments
 (0)