๐Ÿ“ฆ airbnb / lunar

๐Ÿ“„ global.d.ts ยท 81 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81/* eslint-disable */

declare module 'fake-indexeddb';
declare module 'full-icu';
declare module ':storybook/components/*';
declare module '*.jpg';
declare module '*.png';

declare const __DEV__: boolean;
declare const jsdom: any;
declare const action: (key: string) => (...args: unknown[]) => void;

// MONKEY PATCHING

type RequestIdleCallbackOptions = {
  timeout: number;
};

type RequestIdleCallbackDeadline = {
  readonly didTimeout: boolean;
  timeRemaining: (() => number);
};

interface ResizeObserverEntry {
  readonly contentRect: DOMRectInit;
  readonly target: HTMLElement;
  new (target: HTMLElement): ResizeObserverEntry;
}

interface ResizeObserver {
  new (
    callback: (entries: ResizeObserverEntry[], observer: ResizeObserver) => void,
  ): ResizeObserver;
  observe(target: HTMLElement): void;
  unobserve(target: HTMLElement): void;
  disconnect(): void;
}

interface Window {
  __APOLLO_CLIENT__: any;
  Notification: Notification;
  ResizeObserver: ResizeObserver;
  requestIdleCallback: (
    callback: ((deadline: RequestIdleCallbackDeadline) => void),
    opts?: RequestIdleCallbackOptions,
  ) => number;
  cancelIdleCallback: ((handle: number) => void);
}

interface WindowEventMap {
  cut: ClipboardEvent;
  copy: ClipboardEvent;
  paste: ClipboardEvent;
}

interface MouseEvent {
  trackingContext?: string[];
}

interface KeyboardEvent {
  trackingContext?: string[];
}

// One of our transitive dependencies installs @types/node, which overtakes our `global`
// variable, and we can't do anything about it. So to get around it, we need to modify
// and monkeypatch the NodeJS global for our needs. This is hacky, I know.
declare namespace NodeJS {
  interface Global {
    __REDUX_DEVTOOLS_EXTENSION_COMPOSE__: any;
    ga?: UniversalAnalytics.ga;
    location: Location;
    navigator: Navigator;
    newrelic: NewRelic.Browser;
    // Tests
    indexedDB: IDBFactory;
    jsdom: any;
    IntersectionObserver: IntersectionObserver;
    Notification: Notification;
  }
}