metaTitle should be recognized as string | undefined.
route.meta should be typed as RouteMeta | undefined (and be undefined when there is no meta defined for the route)
Actual behavior
route.meta is an empty object that does not conform to the RouteMeta interface.
metaTitle is recognized as string, despite being undefined.
Additional information
RouteRecordRaw's meta property is optional. However the route returned by useRoute always contains a meta object and in this case is empty.
useRoute() returns a RouteLocationNormalizedLoaded which inherits meta: RouteMeta from MatcherLocation. This should be marked as meta: Partial<RouteMeta>.
useRouter().getRoutes() returns a RouteRecordNormalized[] which defines meta: Exclude<_RouteRecordBase['meta'], void>. This shouldb e defined as meta: Partial<Exclude<_RouteRecordBase['meta'], void>>
The fact that route.meta is always defined even for routes that don't have a defined meta object is likely an artifact due to the way meta data is inherited by nested routes, so I understand if it ends up being too difficult to set that field to undefined if the route (and its parents) didn't have any meta defined.
Making the meta property in _RouteRecordBase required would allow us to require meta data to be present when defining routes, but may be annoying for those that don't need metadata, but this would be the most type-safe way of enforcing metadata, though would require behavioral changes.
Marking the above mentioned properties as Partial is the correct way to type the current behavior that is "We know you've made these RouteMeta properties required, but that doesn't mean they'll be on this route".
meta is always defined because it’s more convenient
the type is currently more permissive than it should be changing it would be a breaking change. In a future major version the RouteMeta should extend Record<unknown, unknown> or similar It already does
in your case, you should define title as an optional property title?:. Using Partial would not require the property.
This is tracked but it will have to wait a major due to being a breaking change
Reproduction
Define required fields on
RouteMeta
, but omitmeta
from routes.Steps to reproduce the bug
router.ts
App.vue
Expected behavior
Either
metaTitle
should be recognized asstring | undefined
.route.meta
should be typed asRouteMeta | undefined
(and be undefined when there is nometa
defined for the route)Actual behavior
route.meta
is an empty object that does not conform to theRouteMeta
interface.metaTitle
is recognized asstring
, despite being undefined.Additional information
RouteRecordRaw
'smeta
property is optional. However the route returned byuseRoute
always contains ameta
object and in this case is empty.useRoute()
returns aRouteLocationNormalizedLoaded
which inheritsmeta: RouteMeta
fromMatcherLocation
. This should be marked asmeta: Partial<RouteMeta>
.useRouter().getRoutes()
returns aRouteRecordNormalized[]
which definesmeta: Exclude<_RouteRecordBase['meta'], void>
. This shouldb e defined asmeta: Partial<Exclude<_RouteRecordBase['meta'], void>>
The fact that
route.meta
is always defined even for routes that don't have a defined meta object is likely an artifact due to the way meta data is inherited by nested routes, so I understand if it ends up being too difficult to set that field toundefined
if the route (and its parents) didn't have any meta defined.Making the
meta
property in_RouteRecordBase
required would allow us to require meta data to be present when defining routes, but may be annoying for those that don't need metadata, but this would be the most type-safe way of enforcing metadata, though would require behavioral changes.Marking the above mentioned properties as
Partial
is the correct way to type the current behavior that is "We know you've made these RouteMeta properties required, but that doesn't mean they'll be on this route".