global.d.ts 4.4 KB

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