V
V
VladiGG2021-04-14 20:38:55
JavaScript
VladiGG, 2021-04-14 20:38:55

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 'Имя компонента'.


My tsconfig
{
  "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"
  ]
}


My shims file for the router
import { VueRouter } from "vue-router/types/router";
import { Route } from "vue-router";

declare module "vue/types/vue" {
  interface VueConstructor {
    $router: VueRouter;
    $route: Route;
  }
}


the files are in project_name/src/@types/

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question