-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: make typed useRoute(currentRouteName)
return children route types as well
#2475
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
Conversation
…ypes as well
✅ Deploy Preview for vue-router canceled.
|
commit: |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2475 +/- ##
=======================================
Coverage 94.89% 94.89%
=======================================
Files 34 34
Lines 2998 2998
Branches 845 845
=======================================
Hits 2845 2845
Misses 150 150
Partials 3 3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is ready!
@@ -17,16 +13,30 @@ export interface RouteRecordInfo< | |||
// TODO: could probably be inferred from the Params | |||
ParamsRaw extends RouteParamsRawGeneric = RouteParamsRawGeneric, | |||
Params extends RouteParamsGeneric = RouteParamsGeneric, | |||
Meta extends RouteMeta = RouteMeta, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed this type param because it was never used and I figured it's safer to add it back later if needed than leaving an unused type param that can eventually be used. I marked this as a fix because the leftover type param should have never been released in the first place
In an app (with a typed router) where route
/a/b
is a child of route/a
, this makesuseRoute('/a')
returnRouteLocationNormalizedLoadedTyped<RouteNamedMap, "/a"> | RouteLocationNormalizedLoadedTyped<RouteNamedMap, "/a/b">
.It works in a recursive manner, so whenever route
/a/b/c
is added as a child of/a/b
,useRoute('/a')
will returnRouteLocationNormalizedLoadedTyped<RouteNamedMap, "/a"> | RouteLocationNormalizedLoadedTyped<RouteNamedMap, "/a/b">
| RouteLocationNormalizedLoadedTyped<RouteNamedMap, "/a/b/c">`.Of course
useRoute('/a/b/c')
will only returnRouteLocationNormalizedLoadedTyped<RouteNamedMap, "/a/b/c">
.Note
This PR is intended to be paired with the following
unplugin-vue-router
PR: posva/unplugin-vue-router#602That PR changes the DTS generation to include
RouteMeta
and a union of the children route's names as generics to everyRouteRecordInfo
type.