global.d.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /**
  2. * globals.d.ts —— UMD 全局变量的 TypeScript 声明(README §3.3-1「禁 import 框架」的类型侧配套)。
  3. *
  4. * 背景:框架运行时全部走 index.html 引入的 UMD 全局(Vue / VueRouter / Pinia / ElementPlus / axios),
  5. * 业务代码不 import 框架模块。
  6. * 落点说明:本文件放**仓库根**(而非 src/types)——shims/ 目录在 src 之外,
  7. * 若声明放 src 内则 shims 文件不生效(全局声明只对 include 范围生效)。
  8. * 本文件做两件事:
  9. * ① 声明 5 个 UMD 全局常量(typeof 引自已安装的同版本 dev 依赖,类型与运行时一一对应);
  10. * ② 声明 vite define 注入的组合式 API 裸标识符(ref / computed / onMounted …),
  11. * 使业务代码里"裸写 ref()"既能通过类型检查、又能在运行时命中 Vue 全局。
  12. *
  13. * 版本纪律:dev 依赖版本必须与 index.html 头部"vendor 版本表"保持一致(升级走 README §1.5 五步流程)。
  14. */
  15. import type { AxiosStatic } from 'axios';
  16. import type { Language } from 'element-plus';
  17. import type * as PiniaNS from 'pinia';
  18. import type * as VueNS from 'vue';
  19. import type * as VueRouterNS from 'vue-router';
  20. declare global {
  21. // —— UMD 全局常量(index.html 按序注入)——
  22. const Vue: typeof VueNS;
  23. /**
  24. * vue-demi 桥接全局(vendor/vue-demi@0.14.10 注入):读 globalThis.Vue 后把 Vue API
  25. * 镜像到本全局。纯 Vue3 下等价于 re-export Vue;业务代码不直接引用,
  26. * 仅供 pinia IIFE 构建内部取用(pinia 官方构建硬依赖 VueDemi 全局)。声明仅为全局清单完整。
  27. */
  28. var VueDemi: typeof VueNS;
  29. const VueRouter: typeof VueRouterNS;
  30. const Pinia: typeof PiniaNS;
  31. /** var 声明(而非 const):允许 globalThis.ElementPlus 属性式访问(http.ts 拦截器内)+ 模板回退解析 */
  32. var ElementPlus: typeof import('element-plus');
  33. /** Element Plus 简体中文 locale(vendor/element-plus@2.14.7/locale/zh-cn.min.js 注入) */
  34. var ElementPlusLocaleZhCn: Language;
  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 {};