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

$route.meta types #2331

Closed
backbone87 opened this issue Aug 1, 2018 · 4 comments
Closed

$route.meta types #2331

backbone87 opened this issue Aug 1, 2018 · 4 comments

Comments

@backbone87
Copy link

What problem does this feature solve?

Currently the meta field is typed to any. It would be nice, if we could provide a type for it. I tried an ambient module, but couldnt get it to work, so a generic type variable may needs to be introduced.

What does the proposed API look like?

interface RouteConfig<M = any> { meta?: M, ... }

Also the using types may need adjustments.

@posva
Copy link
Member

posva commented Aug 2, 2018

The meta object can be different per route, otherwise, its type would end up in making every single field optional, forcing you to check everytime the properties

@posva posva closed this as completed Aug 2, 2018
@backbone87
Copy link
Author

backbone87 commented Aug 2, 2018

But we dont even have this decision...

Also some structure like this reduces the checks to a minimum:

  interface RouteMeta {
    navigation?: RouteNavigation,
    auth?: RouteAuth,
  }

The check doesnt change at all, if we want to check RouteAuth in a hook, because i need to check for route.meta && route.meta.auth anyway (even when the meta field type is any). Same for a navigation that is rendered from the route set.

@nicky1038
Copy link

nicky1038 commented Aug 5, 2020

@posva I agree with @backbone87. Providing an imperfect but still working ability to declare meta field type as a partial interface is way better than leave this field totally untyped. It won't force users to check properties more than how much they do it now, as an object of any type should be fully checked too.

The main potential problem I can see there is that the implementation of this feature would not be as easy as it seems to be. Vue-router itself creates ambient type declarations for Vue with $route and $router properties, so it will be necessary to add a new generic parameter (type of meta field) to Vue interface.

@posva
Copy link
Member

posva commented Aug 5, 2020

Let's keep the discussion at #3183

@vuejs vuejs locked and limited conversation to collaborators Aug 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants