The simplest solution to this problem I have found is manually importing the modified type and type casting the data to it.
So in this case I want to pass in the to.meta
from my Nuxt middleware into the typed function. tsserver and vue-tsc are both telling me that to.meta
is of the vue-router
type RouteMeta
which has been modified in my index.d.ts
. So i adjusted my middleware to look like this:
import type { RouteMeta } from "vue-router";
// global authorization middleware that runs on every route to check if user is entitled to be there
export default defineNuxtRouteMiddleware(
(to) => {
// ...
const isAuthorizedTo = useAuthStore().isAuthorizedTo(to.meta as RouteMeta);
// ...
},
);
I am typecasting from RouteMeta
to RouteMeta
, which feels redundant and unnecessary, but it does solve the compilation and language server issues.