global.d.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. gtag: Function;
  15. }
  16. // https://github.com/facebook/create-react-app/blob/ddcb7d5/packages/react-scripts/lib/react-app.d.ts
  17. declare namespace NodeJS {
  18. interface ProcessEnv {
  19. readonly REACT_APP_BACKEND_V1_GET_URL: string;
  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. // PNG encoding/decoding
  42. // -----------------------------------------------------------------------------
  43. type TEXtChunk = { name: "tEXt"; data: Uint8Array };
  44. declare module "png-chunk-text" {
  45. function encode(
  46. name: string,
  47. value: string,
  48. ): { name: "tEXt"; data: Uint8Array };
  49. function decode(data: Uint8Array): { keyword: string; text: string };
  50. }
  51. declare module "png-chunks-encode" {
  52. function encode(chunks: TEXtChunk[]): Uint8Array;
  53. export = encode;
  54. }
  55. declare module "png-chunks-extract" {
  56. function extract(buffer: Uint8Array): TEXtChunk[];
  57. export = extract;
  58. }
  59. // -----------------------------------------------------------------------------
  60. // -----------------------------------------------------------------------------
  61. // type getter for interface's callable type
  62. // src: https://stackoverflow.com/a/58658851/927631
  63. // -----------------------------------------------------------------------------
  64. type SignatureType<T> = T extends (...args: infer R) => any ? R : never;
  65. type CallableType<T extends (...args: any[]) => any> = (
  66. ...args: SignatureType<T>
  67. ) => ReturnType<T>;
  68. // --------------------------------------------------------------------------—
  69. // Type for React.forwardRef --- supply only the first generic argument T
  70. type ForwardRef<T, P = any> = Parameters<
  71. CallableType<React.ForwardRefRenderFunction<T, P>>
  72. >[1];
  73. // --------------------------------------------------------------------------—
  74. interface Blob {
  75. handle?: import("browser-nativefs").FileSystemHandle;
  76. name?: string;
  77. }