global.d.ts 3.9 KB

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