global.d.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /**
  2. * global.d.ts —— UMD 全局变量 + vite define 裸标识符的 TypeScript 声明(移动端混合机制类型侧配套)。
  3. *
  4. * 背景(移动端混合方案,README §1.x):
  5. * - **Vue 系走 UMD 全局**:Vue / VueDemi / VueRouter / Pinia / axios 由 index.html 按序引入
  6. * (vendor/ 自托管,同 PC 端纪律),业务代码不 import 这些框架模块;
  7. * - **Vant 走 npm 编译**:Vant 4 官方无 UMD 构建(仅 es/lib),只能 `import Vant from 'vant'`
  8. * 编译进 bundle,由 vant 包自带 TS 类型覆盖——故本文件**不声明 Vant 全局**(与 PC 端 ElementPlus
  9. * 走 UMD 全局 + 此文件声明的差异点)。
  10. *
  11. * 落点:本文件放**仓库根**(monorepo 唯一类型检查入口 tsconfig.json 的 include 覆盖它 + shims/ +
  12. * packages/shared/src + apps/{端}/src)。
  13. * 做两件事:
  14. * ① 声明 5 个 UMD 全局(Vue/VueDemi/VueRouter/Pinia/axios,typeof 引自同版本 dev 依赖);
  15. * ② 声明 vite define 注入的组合式 API 裸标识符(ref / computed / onMounted …),
  16. * 使业务代码"裸写 ref()"既过类型检查、又运行时命中 Vue 全局。
  17. *
  18. * 版本纪律:dev 依赖版本必须与 index.html 头部"vendor 版本表"一致(升级走框架升级流程)。
  19. */
  20. import type { AxiosStatic } from 'axios';
  21. import type * as PiniaNS from 'pinia';
  22. import type * as VueNS from 'vue';
  23. import type * as VueRouterNS from 'vue-router';
  24. declare global {
  25. // —— UMD 全局常量(index.html 按序注入;vendor/ 自托管)——
  26. const Vue: typeof VueNS;
  27. /**
  28. * vue-demi 桥接全局(vendor/vue-demi@0.14.10 注入):读 globalThis.Vue 后把 Vue API
  29. * 镜像到本全局。纯 Vue3 下等价于 re-export Vue;业务代码不直接引用,
  30. * 仅供 pinia IIFE 构建内部取用(pinia 官方构建硬依赖 VueDemi 全局)。
  31. */
  32. var VueDemi: typeof VueNS;
  33. const VueRouter: typeof VueRouterNS;
  34. const Pinia: typeof PiniaNS;
  35. /** UMD 全局 axios 是**实例**(root.axios = 默认实例,含 post/get/create),类型 = AxiosStatic */
  36. var axios: AxiosStatic;
  37. // —— vite define 注入的组合式 API 裸标识符(vite.config.ts VUE_APIS 清单与之一一对应)——
  38. const ref: typeof VueNS.ref;
  39. const shallowRef: typeof VueNS.shallowRef;
  40. const reactive: typeof VueNS.reactive;
  41. const shallowReactive: typeof VueNS.shallowReactive;
  42. const readonly: typeof VueNS.readonly;
  43. const shallowReadonly: typeof VueNS.shallowReadonly;
  44. const computed: typeof VueNS.computed;
  45. const watch: typeof VueNS.watch;
  46. const watchEffect: typeof VueNS.watchEffect;
  47. const watchPostEffect: typeof VueNS.watchPostEffect;
  48. const watchSyncEffect: typeof VueNS.watchSyncEffect;
  49. const effectScope: typeof VueNS.effectScope;
  50. const customRef: typeof VueNS.customRef;
  51. const triggerRef: typeof VueNS.triggerRef;
  52. const toRef: typeof VueNS.toRef;
  53. const toRefs: typeof VueNS.toRefs;
  54. const toRaw: typeof VueNS.toRaw;
  55. const toValue: typeof VueNS.toValue;
  56. const markRaw: typeof VueNS.markRaw;
  57. const isRef: typeof VueNS.isRef;
  58. const isReactive: typeof VueNS.isReactive;
  59. const isReadonly: typeof VueNS.isReadonly;
  60. const isVNode: typeof VueNS.isVNode;
  61. const unref: typeof VueNS.unref;
  62. const onMounted: typeof VueNS.onMounted;
  63. const onBeforeMount: typeof VueNS.onBeforeMount;
  64. const onUnmounted: typeof VueNS.onUnmounted;
  65. const onBeforeUnmount: typeof VueNS.onBeforeUnmount;
  66. const onUpdated: typeof VueNS.onUpdated;
  67. const onBeforeUpdate: typeof VueNS.onBeforeUpdate;
  68. const onActivated: typeof VueNS.onActivated;
  69. const onDeactivated: typeof VueNS.onDeactivated;
  70. const onErrorCaptured: typeof VueNS.onErrorCaptured;
  71. const onRenderTracked: typeof VueNS.onRenderTracked;
  72. const onRenderTriggered: typeof VueNS.onRenderTriggered;
  73. const onScopeDispose: typeof VueNS.onScopeDispose;
  74. const nextTick: typeof VueNS.nextTick;
  75. const createApp: typeof VueNS.createApp;
  76. const inject: typeof VueNS.inject;
  77. const provide: typeof VueNS.provide;
  78. const h: typeof VueNS.h;
  79. // —— Vue Router(define 注入为 VueRouter.*)——
  80. const createRouter: typeof VueRouterNS.createRouter;
  81. const createWebHashHistory: typeof VueRouterNS.createWebHashHistory;
  82. const createWebHistory: typeof VueRouterNS.createWebHistory;
  83. const useRoute: typeof VueRouterNS.useRoute;
  84. const useRouter: typeof VueRouterNS.useRouter;
  85. // —— Pinia(define 注入为 Pinia.*)——
  86. const defineStore: typeof PiniaNS.defineStore;
  87. const createPinia: typeof PiniaNS.createPinia;
  88. const storeToRefs: typeof PiniaNS.storeToRefs;
  89. }
  90. export {};