Skip to content

Commit

Permalink
fix(types): correct types in navigation guards
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Jan 6, 2024
1 parent a8c813a commit 3f01155
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/type-extensions/navigationGuards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,33 @@ type NavigationGuardReturn =
export interface NavigationGuardWithThis<T> {
(
this: T,
to: _RouteLocationNormalized,
from: _RouteLocationNormalizedLoaded,
// intentionally not typed to make people use the return
next: NavigationGuardNext
): NavigationGuardReturn | Promise<NavigationGuardReturn>
}

/**
* In `router.beforeResolve((to) => {})`, the `to` is typed as `RouteLocationNormalizedLoaded`, not
* `RouteLocationNormalized` like in `router.beforeEach()`. In practice it doesn't change much as users do not rely on
* the difference between them but if we update the type in vue-router, we will have to update this type too.
* @internal
*/
export interface _NavigationGuardResolved {
(
this: undefined,
to: _RouteLocationNormalizedLoaded,
from: _RouteLocationNormalizedLoaded,
// intentionally not typed to make people use the other version
// intentionally not typed to make people use the return
next: NavigationGuardNext
): NavigationGuardReturn | Promise<NavigationGuardReturn>
}

export interface NavigationGuard {
(
to: _RouteLocationNormalized,
from: _RouteLocationNormalized,
from: _RouteLocationNormalizedLoaded,
// intentionally not typed to make people use the other version
next: NavigationGuardNext
): NavigationGuardReturn | Promise<NavigationGuardReturn>
Expand Down

0 comments on commit 3f01155

Please sign in to comment.