Skip to content

Creating a type declaration for next #2758

@Midnighter

Description

@Midnighter

What problem does this feature solve?

At the moment there is a type definition for NavigationGuard in router.d.ts. This works nicely. Within that, the next argument is a function that accepts a union of different types as argument.

next: (to?: RawLocation | false | ((vm: V) => any) | void) => void

I think it'd be neat to easily use this just like the Route interface declaration in, for example, a components navigation guard.

What does the proposed API look like?

Export a type definition maybe called NavigationGuardCallback in router.d.ts.

export type NavigationGuardCallback = (to?: RawLocation | false | ((vm: V) => any) | void) => void;

export type NavigationGuard<V extends Vue = Vue> = (
  to: Route,
  from: Route,
  next: NavigationGuardCallback
) => any;

Activity

posva

posva commented on May 7, 2019

@posva
Member

This will definitely be exposed, not sure about the wording yet

posva

posva commented on May 8, 2019

@posva
Member

There was #2497, the wording isn't good though

MartinYounghoonKim

MartinYounghoonKim commented on Sep 2, 2019

@MartinYounghoonKim

@posva
That PR has confilcts, but the creator of that pr no longer takes any action.

added a commit that references this issue on Sep 2, 2019
voool

voool commented on Sep 10, 2019

@voool

Fwiw, if anyone wants a workaround that doesn't involve creating their own copy of the next interface, see #2497 (comment)

As a workaround, to grab the next interface with Typescript you can do

import { NavigationGuard } from 'vue-router';
type Next = Parameters<NavigationGuard>[2];
added
fixed on 4.xThis issue has been already fixed on the v4 but exists in v3
on Jul 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    TypescriptTypescript related issuesfixed on 4.xThis issue has been already fixed on the v4 but exists in v3has PR

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Midnighter@posva@MartinYounghoonKim@voool

        Issue actions

          Creating a type declaration for `next` · Issue #2758 · vuejs/vue-router