global.d.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import type {
  2. ComponentPublicInstance,
  3. FunctionalComponent,
  4. VNodeChild,
  5. PropType as VuePropType,
  6. } from 'vue'
  7. // declare global 在具有 import 或 export 声明全局范围内的事物的文件中使用。
  8. // 这在包含 import 或 export 因为此类文件被视为模块的文件中是必需的,并且在模块中声明的任何内容都在模块范围内。
  9. // 在不是模块的文件中使用 declare global(即不包含import / export)是错误的,因为这样的文件中的所有内容都在全局范围内。
  10. declare global {
  11. const __APP_INFO__: {
  12. pkg: {
  13. name: string
  14. version: string
  15. dependencies: Recordable<string>
  16. devDependencies: Recordable<string>
  17. }
  18. lastBuildTime: string
  19. }
  20. // vue
  21. type PropType<T> = VuePropType<T>
  22. type VueNode = VNodeChild | JSX.Element
  23. export type Writable<T> = {
  24. -readonly [P in keyof T]: T[P];
  25. }
  26. type Nullable<T> = T | null
  27. type NonNullable<T> = T extends null | undefined ? never : T
  28. type Recordable<T = any> = Record<string, T>
  29. interface ReadonlyRecordable<T = any> {
  30. readonly [key: string]: T
  31. }
  32. interface Indexable<T = any> {
  33. [key: string]: T
  34. }
  35. type DeepPartial<T> = {
  36. [P in keyof T]?: DeepPartial<T[P]>;
  37. }
  38. type TimeoutHandle = ReturnType<typeof setTimeout>
  39. type IntervalHandle = ReturnType<typeof setInterval>
  40. interface ChangeEvent extends Event {
  41. target: HTMLInputElement
  42. }
  43. interface WheelEvent {
  44. path?: EventTarget[]
  45. }
  46. interface ImportMetaEnv extends ViteEnv {
  47. __: unknown
  48. }
  49. interface ViteEnv {
  50. VITE_PORT: number
  51. VITE_USE_MOCK: boolean
  52. VITE_PUBLIC_PATH: string
  53. VITE_GLOB_APP_TITLE: string
  54. VITE_GLOB_APP_SHORT_NAME: string
  55. VITE_DROP_CONSOLE: boolean
  56. VITE_GLOB_PROD_MOCK: boolean
  57. VITE_GLOB_IMG_URL: string
  58. VITE_PROXY: [string, string][]
  59. VITE_BUILD_COMPRESS: 'gzip' | 'brotli' | 'none'
  60. VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE: boolean
  61. }
  62. }
  63. declare module 'vue' {
  64. export type JSXComponent<Props = any> =
  65. | { new (): ComponentPublicInstance<Props> }
  66. | FunctionalComponent<Props>
  67. }