pnpm 导致d.ts中@vue/runtime-core 申明失效问题解决方案

2,315 阅读1分钟

使用pnpm进行包管理项目中,@vue/runtime-core 类型申明失效问题

问题

近日再构建vue3的前端项目中,使用了pnpm进行包管理,然后在构建项目中要在vue实例中挂载全局属性,以便于业务开发,但是发现在申明自定义属性(ComponentCustomProperties)后,vue文件中不生效,ts报错,如图

image.png

更新 2024.1

不用对@vue/runtime-core模块做ts类型合并,对vue模块操作就行了。

可以替换成如下

declare module 'vue' {
  interface ComponentCustomProperties {
    $api: typeof ApiContainer;
    $sensors: typeof sensors;
    $xxx: xxx
  }
}

官方文档里有写

Vue官网文档-扩展全局属性