vue3 + typescript:TS2345:“路由器”类型的参数不可分配给“Plugin_2”类型的参数

问题描述 投票:0回答:3

在我们的yarn多工作空间项目中,我们在最新版本的vue中遇到了一个非常奇怪的打字稿构建异常:

TS2345: Argument of type 'Router' is not assignable to parameter of type 'Plugin_2'.
  Type 'Router' is not assignable to type '{ install: PluginInstallFunction; }'.
    Types of property 'install' are incompatible.
      Type '(app: App<any>) => void' is not assignable to type 'PluginInstallFunction'.
        Types of parameters 'app' and 'app' are incompatible.
          Type 'import("/node_modules/@vue/runtime-core/dist/runtime-core").App<any>' is not assignable to type 'import("/node_modules/@vue/runtime-core/dist/runtime-core").App<any>'.

对我来说,它们看起来确实是一样的......

package.json的相关部分:

{
   "dependencies": {
     "vue": "^3.2.31",
     "vue-router": "4.0.12",
     "@typescript-eslint/eslint-plugin": "^4.18.0",
     "@typescript-eslint/parser": "^4.18.0",
     "ts-node": "^8.10.2",
     "typescript": "~4.1.5"
   }
}

有人以前遇到过这个问题,并且知道如何解决它,而不需要经历打开 vue core 票证的漫长过程吗?

vue.js vue-router
3个回答
3
投票

我们让它看起来像一根奇怪的纱线......

我们现在将 vue 的所有依赖项升级为

"vue": "^3.2.29"
,错误消失了。


2
投票

就我而言,安装Element plus UI时出现错误。我决定在 tsconfig.json 中设置类型

"types": ["element-plus/global"]

更新: 解决指定类型的问题也同样容易

as any
。我不知道这有多正确,但打字稿并不总是显示错误。例如:
createApp(App).use(i18n as any).use(ElementPlus).use(router as any).use(createPinia() as any).mount('#app')


0
投票

就我而言,我发现应用程序和插件之间有不同版本的 Vue。

应用程序已安装

[email protected]
,插件已安装
[email protected]
,还有另一个插件
[email protected]

© www.soinside.com 2019 - 2024. All rights reserved.