Answer the question
In order to leave comments, you need to log in
Why doesn't TS see the $router type in a single file component?
I am working on a project using Vue 2 and TS. When compiling the code, the following errors are thrown:
Property '$route' does not exist on type 'Имя компонента'.
Property "$router" does not exist on type 'Имя компонента'.
{
"compilerOptions": {
"target": "es5",
"module": "esnext",
"strict": true,
"jsx": "preserve",
"importHelpers": true,
"moduleResolution": "node",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"sourceMap": true,
"noImplicitThis": false,
"downlevelIteration": true,
"baseUrl": ".",
"typeRoots": [
"./node_modules/@types",
"./src/@types/",
],
"types": [
"webpack-env"
],
"paths": {
"@/*": [
"src/*"
]
},
"lib": [
"esnext",
"dom",
"dom.iterable",
"scripthost"
]
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.vue",
"tests/**/*.ts",
"tests/**/*.tsx"
],
"exclude": [
"node_modules"
]
}
import { VueRouter } from "vue-router/types/router";
import { Route } from "vue-router";
declare module "vue/types/vue" {
interface VueConstructor {
$router: VueRouter;
$route: Route;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question