global.d.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import type {
  2. ComponentRenderProxy,
  3. VNode,
  4. VNodeChild,
  5. ComponentPublicInstance,
  6. FunctionalComponent,
  7. PropType as VuePropType,
  8. } from 'vue';
  9. declare global {
  10. const __APP_INFO__: {
  11. pkg: {
  12. name: string;
  13. version: string;
  14. dependencies: Recordable<string>;
  15. devDependencies: Recordable<string>;
  16. };
  17. lastBuildTime: string;
  18. };
  19. // declare interface Window {
  20. // // Global vue app instance
  21. // __APP__: App<Element>;
  22. // }
  23. // 此处 重新定义 ImportMeta 避免 ts 类型报错
  24. // 目前框架只用到 env 和 glob
  25. interface ImportMeta {
  26. env: Record<string, string>;
  27. glob: Record<function>;
  28. }
  29. // vue
  30. declare type PropType<T> = VuePropType<T>;
  31. declare type VueNode = VNodeChild | JSX.Element;
  32. export type Writable<T> = {
  33. -readonly [P in keyof T]: T[P];
  34. };
  35. declare type Nullable<T> = T | null;
  36. declare type NonNullable<T> = T extends null | undefined ? never : T;
  37. declare type Recordable<T = any> = Record<string, T>;
  38. declare type ReadonlyRecordable<T = any> = {
  39. readonly [key: string]: T;
  40. };
  41. declare type Indexable<T = any> = {
  42. [key: string]: T;
  43. };
  44. declare type DeepPartial<T> = {
  45. [P in keyof T]?: DeepPartial<T[P]>;
  46. };
  47. declare type TimeoutHandle = ReturnType<typeof setTimeout>;
  48. declare type IntervalHandle = ReturnType<typeof setInterval>;
  49. declare interface ChangeEvent extends Event {
  50. target: HTMLInputElement;
  51. }
  52. declare interface WheelEvent {
  53. path?: EventTarget[];
  54. }
  55. interface ImportMetaEnv extends ViteEnv {
  56. __: unknown;
  57. }
  58. declare interface ViteEnv {
  59. VITE_PORT: number;
  60. VITE_USE_MOCK: boolean;
  61. VITE_GLOB_APP_TITLE: string;
  62. VITE_GLOB_APP_SHORT_NAME: string;
  63. VITE_DROP_CONSOLE: boolean;
  64. VITE_GLOB_PROD_MOCK: boolean;
  65. VITE_GLOB_IMG_URL: string;
  66. VITE_PROXY: [string, string][];
  67. VITE_BUILD_COMPRESS: 'gzip' | 'brotli' | 'none';
  68. VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE: boolean;
  69. }
  70. declare interface SelectOption {
  71. value: string | number | boolean | object;
  72. label: string | number;
  73. disabled: boolean;
  74. }
  75. declare function parseInt(s: string | number, radix?: number): number;
  76. declare function parseFloat(string: string | number): number;
  77. namespace JSX {
  78. // tslint:disable no-empty-interface
  79. type Element = VNode;
  80. // tslint:disable no-empty-interface
  81. type ElementClass = ComponentRenderProxy;
  82. interface ElementAttributesProperty {
  83. $props: any;
  84. }
  85. interface IntrinsicElements {
  86. [elem: string]: any;
  87. }
  88. interface IntrinsicAttributes {
  89. [elem: string]: any;
  90. }
  91. }
  92. }
  93. declare module 'vue' {
  94. export type JSXComponent<Props = any> =
  95. | { new (): ComponentPublicInstance<Props> }
  96. | FunctionalComponent<Props>;
  97. }