【问题标题】:Error in Vue3 - Argument of type 'typeof import("../dist/vue")' is not assignable to parameter of type 'PublicAPIComponent'Vue3 中的错误 - 'typeof import("../dist/vue")' 类型的参数不可分配给 'PublicAPIComponent' 类型的参数
【发布时间】:2020-09-24 18:00:04
【问题描述】:

我使用 cli v4.4.1 安装 vue。

之后我运行这个命令来更新到 Vue3:vue add vue-next

当我打开main.ts 时,我收到打字稿错误:

Argument of type 'typeof import("c:/../vue-app/node_modules/vue/dist/vue")' is not assignable to parameter of type 'PublicAPIComponent'.

我需要做什么来解决这个错误?

【问题讨论】:

  • 此处相同,因此无法为应用程序提供服务
  • 解决方法:createApp(app as any)。 Vue 团队发布了 vue3,但我们不费吹灰之力就发现了一个问题 :(

标签: typescript vue.js


【解决方案1】:

我通过更新 src/shims-vue.d.ts 中 *.vue 模块的定义文件解决了这个问题:

declare module "*.vue" {
  import { defineComponent } from "vue";
  const component: ReturnType<typeof defineComponent>;
  export default component;
}

来源:https://dev.to/lmillucci/building-a-vue-3-component-with-typescript-4pge

【讨论】:

  • 对我不起作用。因此,我必须使用 cmets 的 Jon Sud 建议的解决方法:createApp(app as any)
  • 不工作并且转换为any首先破坏了使用 ts 的目的
猜你喜欢
  • 1970-01-01
  • 2020-01-06
  • 1970-01-01
  • 2018-08-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-15
  • 2017-12-08
相关资源
最近更新 更多