global.d.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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_V1_GET_URL: string;
  21. readonly REACT_APP_BACKEND_V2_GET_URL: string;
  22. readonly REACT_APP_BACKEND_V2_POST_URL: string;
  23. readonly REACT_APP_SOCKET_SERVER_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 ResolutionType<T extends (...args: any) => any> = T extends (
  34. ...args: any
  35. ) => Promise<infer R>
  36. ? R
  37. : any;
  38. // https://github.com/krzkaczor/ts-essentials
  39. type MarkOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
  40. type MarkRequired<T, RK extends keyof T> = Exclude<T, RK> &
  41. Required<Pick<T, RK>>;
  42. // PNG encoding/decoding
  43. // -----------------------------------------------------------------------------
  44. type TEXtChunk = { name: "tEXt"; data: Uint8Array };
  45. declare module "png-chunk-text" {
  46. function encode(
  47. name: string,
  48. value: string,
  49. ): { name: "tEXt"; data: Uint8Array };
  50. function decode(data: Uint8Array): { keyword: string; text: string };
  51. }
  52. declare module "png-chunks-encode" {
  53. function encode(chunks: TEXtChunk[]): Uint8Array;
  54. export = encode;
  55. }
  56. declare module "png-chunks-extract" {
  57. function extract(buffer: Uint8Array): TEXtChunk[];
  58. export = extract;
  59. }
  60. // -----------------------------------------------------------------------------
  61. // -----------------------------------------------------------------------------
  62. // type getter for interface's callable type
  63. // src: https://stackoverflow.com/a/58658851/927631
  64. // -----------------------------------------------------------------------------
  65. type SignatureType<T> = T extends (...args: infer R) => any ? R : never;
  66. type CallableType<T extends (...args: any[]) => any> = (
  67. ...args: SignatureType<T>
  68. ) => ReturnType<T>;
  69. // --------------------------------------------------------------------------—
  70. // Type for React.forwardRef --- supply only the first generic argument T
  71. type ForwardRef<T, P = any> = Parameters<
  72. CallableType<React.ForwardRefRenderFunction<T, P>>
  73. >[1];
  74. // --------------------------------------------------------------------------—
  75. interface Blob {
  76. handle?: import("browser-fs-acces").FileSystemHandle;
  77. name?: string;
  78. }
  79. declare module "*.scss";