Bug 1871127 - Add tsconfig, basic types, and fix or ignore remaining type errors...
[gecko.git] / toolkit / components / extensions / types / gecko.ts
blobf6b5190f8d29c8efbb57598b088a08e5aabb0b41
1 /**
2  * Global Gecko type declarations.
3  */
5 // @ts-ignore
6 import type { CiClass } from "lib.gecko.xpidl"
8 declare global {
9   // Other misc types.
10   type Browser = InstanceType<typeof XULBrowserElement>;
11   type bytestring = string;
12   type callback = (...args: any[]) => any;
13   type ColorArray = number[];
14   type integer = number;
15   type JSONValue = null | boolean | number | string | JSONValue[] | { [key: string]: JSONValue };
17   interface Document {
18     createXULElement(name: string): Element;
19     documentReadyForIdle: Promise<void>;
20   }
21   interface EventTarget {
22     ownerGlobal: Window;
23   }
24   interface Error {
25     code;
26   }
27   interface ErrorConstructor {
28     new (message?: string, options?: ErrorOptions, lineNo?: number): Error;
29   }
30   interface Window {
31     gBrowser;
32   }
33   // HACK to get the static isInstance for DOMException and Window?
34   interface Object {
35     isInstance(object: any): boolean;
36   }
38   // XPIDL additions/overrides.
40   interface nsISupports {
41     // OMG it works!
42     QueryInterface?<T extends CiClass<nsISupports>>(aCiClass: T): T['prototype'];
43     wrappedJSObject?: object;
44   }
45   interface nsIProperties {
46     get<T extends CiClass<nsISupports>>(prop: string, aCiClass: T): T['prototype'];
47   }
48   interface nsIPrefBranch {
49     getComplexValue<T extends CiClass<nsISupports>>(aPrefName: string, aCiClass: T): T['prototype'];
50   }
51   // TODO: incorporate above into lib.xpidl.d.ts generation, somehow?
53   type Sandbox = typeof globalThis;
54   interface nsIXPCComponents_utils_Sandbox {
55     (principal: nsIPrincipal | nsIPrincipal[], options: object): Sandbox;
56   }
57   interface nsIXPCComponents_Utils {
58     cloneInto<T>(obj: T, ...args: any[]): T;
59     createObjectIn<T>(Sandbox, options?: T): T;
60     exportFunction<T extends callback>(f: T, ...args: any[]): T;
61     getWeakReference<T extends object>(T): { get(): T };
62     readonly Sandbox: nsIXPCComponents_utils_Sandbox;
63     waiveXrays<T>(obj: T): T;
64   }
65   interface nsIDOMWindow extends Window {
66     docShell: nsIDocShell;
67   }
68   interface Document {
69     documentURIObject: nsIURI;
70     createXULElement(name: string): Element;
71   }
73   // nsDocShell is the only thing implementing nsIDocShell, but it also
74   // implements nsIWebNavigation, and a few others, so this is "ok".
75   interface nsIDocShell extends nsIWebNavigation {}
76   interface nsISimpleEnumerator extends Iterable<any> {}
78   namespace Components {
79     type Exception = Error;
80   }
81   namespace UrlbarUtils {
82     type RESULT_TYPE = any;
83     type RESULT_SOURCE = any;
84   }
86   // Various mozilla globals.
87   var Cc, Cr, ChromeUtils, Components, dump, uneval;
89   // [ChromeOnly] WebIDL, to be generated.
90   var BrowsingContext, ChannelWrapper, ChromeWindow, ChromeWorker,
91     ClonedErrorHolder, Glean, InspectorUtils, IOUtils, JSProcessActorChild,
92     JSProcessActorParent, JSWindowActor, JSWindowActorChild,
93     JSWindowActorParent, L10nRegistry, L10nFileSource, Localization,
94     MatchGlob, MatchPattern, MatchPatternSet, PathUtils, PreloadedScript,
95     StructuredCloneHolder, TelemetryStopwatch, WindowGlobalChild,
96     WebExtensionContentScript, WebExtensionParentActor, WebExtensionPolicy,
97     XULBrowserElement, nsIMessageListenerManager;
99   interface XULElement extends Element {}
101   // nsIServices is not a thing.
102   interface nsIServices {
103     scriptloader: mozIJSSubScriptLoader;
104     locale: mozILocaleService;
105     intl: mozIMozIntl;
106     storage: mozIStorageService;
107     appShell: nsIAppShellService;
108     startup: nsIAppStartup;
109     blocklist: nsIBlocklistService;
110     cache2: nsICacheStorageService;
111     catMan: nsICategoryManager;
112     clearData: nsIClearDataService;
113     clipboard: nsIClipboard;
114     console: nsIConsoleService;
115     cookieBanners: nsICookieBannerService;
116     cookies: nsICookieManager & nsICookieService;
117     appinfo: nsICrashReporter & nsIXULAppInfo & nsIXULRuntime;
118     DAPTelemetry: nsIDAPTelemetry;
119     DOMRequest: nsIDOMRequestService;
120     dns: nsIDNSService;
121     dirsvc: nsIDirectoryService & nsIProperties;
122     droppedLinkHandler: nsIDroppedLinkHandler;
123     eTLD: nsIEffectiveTLDService;
124     policies: nsIEnterprisePolicies;
125     env: nsIEnvironment;
126     els: nsIEventListenerService;
127     fog: nsIFOG;
128     focus: nsIFocusManager;
129     io: nsIIOService & nsINetUtil & nsISpeculativeConnect;
130     loadContextInfo: nsILoadContextInfoFactory;
131     domStorageManager: nsIDOMStorageManager & nsILocalStorageManager;
132     logins: nsILoginManager;
133     obs: nsIObserverService;
134     perms: nsIPermissionManager;
135     prefs: nsIPrefBranch & nsIPrefService;
136     profiler: nsIProfiler;
137     prompt: nsIPromptService;
138     sysinfo: nsISystemInfo & nsIPropertyBag2;
139     qms: nsIQuotaManagerService;
140     rfp: nsIRFPService;
141     scriptSecurityManager: nsIScriptSecurityManager;
142     search: nsISearchService;
143     sessionStorage: nsISessionStorageService;
144     strings: nsIStringBundleService;
145     telemetry: nsITelemetry;
146     textToSubURI: nsITextToSubURI;
147     tm: nsIThreadManager;
148     uriFixup: nsIURIFixup;
149     urlFormatter: nsIURLFormatter;
150     uuid: nsIUUIDGenerator;
151     vc: nsIVersionComparator;
152     wm: nsIWindowMediator;
153     ww: nsIWindowWatcher;
154     xulStore: nsIXULStore;
155     ppmm: any;
156     cpmm: any;
157     mm: any;
158   }
160   var Ci: nsIXPCComponents_Interfaces;
161   var Cu: nsIXPCComponents_Utils;
162   var Services: nsIServices;