global.d.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  2. interface Document {
  3. fonts?: {
  4. ready?: Promise<void>;
  5. addEventListener?(
  6. type: "loading" | "loadingdone" | "loadingerror",
  7. listener: (this: Document, ev: Event) => any,
  8. ): void;
  9. };
  10. }
  11. interface Window {
  12. ClipboardItem: any;
  13. __EXCALIDRAW_SHA__: string | undefined;
  14. EXCALIDRAW_ASSET_PATH: string | undefined;
  15. EXCALIDRAW_EXPORT_SOURCE: string;
  16. EXCALIDRAW_THROTTLE_RENDER: boolean | undefined;
  17. gtag: Function;
  18. }
  19. // https://github.com/facebook/create-react-app/blob/ddcb7d5/packages/react-scripts/lib/react-app.d.ts
  20. declare namespace NodeJS {
  21. interface ProcessEnv {
  22. readonly REACT_APP_BACKEND_V2_GET_URL: string;
  23. readonly REACT_APP_BACKEND_V2_POST_URL: string;
  24. readonly REACT_APP_PORTAL_URL: string;
  25. readonly REACT_APP_FIREBASE_CONFIG: string;
  26. }
  27. }
  28. interface Clipboard extends EventTarget {
  29. write(data: any[]): Promise<void>;
  30. }
  31. type Mutable<T> = {
  32. -readonly [P in keyof T]: T[P];
  33. };
  34. type ValueOf<T> = T[keyof T];
  35. type Merge<M, N> = Omit<M, keyof N> & N;
  36. /** utility type to assert that the second type is a subtype of the first type.
  37. * Returns the subtype. */
  38. type SubtypeOf<Supertype, Subtype extends Supertype> = Subtype;
  39. type ResolutionType<T extends (...args: any) => any> = T extends (
  40. ...args: any
  41. ) => Promise<infer R>
  42. ? R
  43. : any;
  44. // https://github.com/krzkaczor/ts-essentials
  45. type MarkOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
  46. type MarkRequired<T, RK extends keyof T> = Exclude<T, RK> &
  47. Required<Pick<T, RK>>;
  48. type MarkNonNullable<T, K extends keyof T> = {
  49. [P in K]-?: P extends K ? NonNullable<T[P]> : T[P];
  50. } & { [P in keyof T]: T[P] };
  51. type NonOptional<T> = Exclude<T, undefined>;
  52. // PNG encoding/decoding
  53. // -----------------------------------------------------------------------------
  54. type TEXtChunk = { name: "tEXt"; data: Uint8Array };
  55. declare module "png-chunk-text" {
  56. function encode(
  57. name: string,
  58. value: string,
  59. ): { name: "tEXt"; data: Uint8Array };
  60. function decode(data: Uint8Array): { keyword: string; text: string };
  61. }
  62. declare module "png-chunks-encode" {
  63. function encode(chunks: TEXtChunk[]): Uint8Array;
  64. export = encode;
  65. }
  66. declare module "png-chunks-extract" {
  67. function extract(buffer: Uint8Array): TEXtChunk[];
  68. export = extract;
  69. }
  70. // -----------------------------------------------------------------------------
  71. // -----------------------------------------------------------------------------
  72. // type getter for interface's callable type
  73. // src: https://stackoverflow.com/a/58658851/927631
  74. // -----------------------------------------------------------------------------
  75. type SignatureType<T> = T extends (...args: infer R) => any ? R : never;
  76. type CallableType<T extends (...args: any[]) => any> = (
  77. ...args: SignatureType<T>
  78. ) => ReturnType<T>;
  79. // --------------------------------------------------------------------------—
  80. // Type for React.forwardRef --- supply only the first generic argument T
  81. type ForwardRef<T, P = any> = Parameters<
  82. CallableType<React.ForwardRefRenderFunction<T, P>>
  83. >[1];
  84. // --------------------------------------------------------------------------—
  85. interface Blob {
  86. handle?: import("browser-fs-acces").FileSystemHandle;
  87. name?: string;
  88. }
  89. declare module "*.scss";
  90. // --------------------------------------------------------------------------—
  91. // ensure Uint8Array isn't assignable to ArrayBuffer
  92. // (due to TS structural typing)
  93. // https://github.com/microsoft/TypeScript/issues/31311#issuecomment-490690695
  94. interface ArrayBuffer {
  95. _brand?: "ArrayBuffer";
  96. }
  97. interface Uint8Array {
  98. _brand?: "Uint8Array";
  99. }
  100. // --------------------------------------------------------------------------—
  101. // https://github.com/nodeca/image-blob-reduce/issues/23#issuecomment-783271848
  102. declare module "image-blob-reduce" {
  103. import { PicaResizeOptions, Pica } from "pica";
  104. namespace ImageBlobReduce {
  105. interface ImageBlobReduce {
  106. toBlob(file: File, options: ImageBlobReduceOptions): Promise<Blob>;
  107. _create_blob(
  108. this: { pica: Pica },
  109. env: {
  110. out_canvas: HTMLCanvasElement;
  111. out_blob: Blob;
  112. },
  113. ): Promise<any>;
  114. }
  115. interface ImageBlobReduceStatic {
  116. new (options?: any): ImageBlobReduce;
  117. (options?: any): ImageBlobReduce;
  118. }
  119. interface ImageBlobReduceOptions extends PicaResizeOptions {
  120. max: number;
  121. }
  122. }
  123. const reduce: ImageBlobReduce.ImageBlobReduceStatic;
  124. export = reduce;
  125. }