I encountered an issue with my Vue file. Here is the code snippet:
import Vue from 'vue';
import VueRouter from 'vue-router';
export default Vue.extend({
name: 'MyComponentsName',
methods: {
doRedirect() {
this.$router.push({ name: 'another-route' });
},
},
});
In addition, I have a shims-vue.d.ts
file:
declare module '*.vue' {
import Vue from 'vue';
export default Vue;
}
declare module 'vue/types/vue' {
import VueRouter from 'vue-router';
interface VueConstructor {
$router: VueRouter;
}
interface Vue {
$router: VueRouter;
}
}
An error message stating:
Property '$router' does not exist on type 'CombinedVueInstance<Vue, ...>
keeps popping up.
I believe that my shims should define what $router
is, but it seems like it's not working as intended. The only workaround I've found so far is using
((this as any).$router as VueRouter).push()
, which doesn't feel ideal...
Is there a way to resolve this warning?