Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a type declaration for next #2758

Open
Midnighter opened this issue May 7, 2019 · 4 comments
Open

Creating a type declaration for next #2758

Midnighter opened this issue May 7, 2019 · 4 comments
Labels
has PR Typescript Typescript related issues

Comments

@Midnighter
Copy link

Midnighter commented May 7, 2019

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;
@posva posva added the Typescript Typescript related issues label May 7, 2019
@posva
Copy link
Member

posva commented May 7, 2019

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

@posva posva added the has PR label May 8, 2019
@posva
Copy link
Member

posva commented May 8, 2019

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

@MartinYounghoonKim
Copy link

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

MartinYounghoonKim added a commit to snack-news/Snack-admin that referenced this issue Sep 2, 2019
@voool
Copy link

voool commented Sep 10, 2019

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];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has PR Typescript Typescript related issues
Projects
None yet
Development

No branches or pull requests

4 participants