From c180df69cb46f560ebb4b69a578eda91c77f47c5 Mon Sep 17 00:00:00 2001 From: Tomislav Jovanovic Date: Wed, 7 Aug 2024 02:01:58 +0000 Subject: [PATCH] Bug 1911476 - Enable basic IDE types support in toolkit/ and browser/ r=mossop Differential Revision: https://phabricator.services.mozilla.com/D218503 --- browser/jsconfig.json | 4 ++++ toolkit/components/extensions/types/globals.ts | 17 ----------------- toolkit/jsconfig.json | 4 ++++ toolkit/moz.build | 3 +++ tools/@types/index.d.ts | 18 ++++++++++++++++++ .../@types/lib.gecko.tweaks.d.ts | 5 ++++- tools/@types/tsconfig.json | 7 +++++++ tools/moz.build | 3 +++ 8 files changed, 43 insertions(+), 18 deletions(-) create mode 100644 browser/jsconfig.json create mode 100644 toolkit/jsconfig.json rename toolkit/components/extensions/types/gecko.ts => tools/@types/lib.gecko.tweaks.d.ts (94%) create mode 100644 tools/@types/tsconfig.json diff --git a/browser/jsconfig.json b/browser/jsconfig.json new file mode 100644 index 000000000000..ceb95a74b8a4 --- /dev/null +++ b/browser/jsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../tools/@types/tsconfig.json", + "include": ["**/*.sys.mjs"] +} diff --git a/toolkit/components/extensions/types/globals.ts b/toolkit/components/extensions/types/globals.ts index eae23ad57f61..ae2b5740809e 100644 --- a/toolkit/components/extensions/types/globals.ts +++ b/toolkit/components/extensions/types/globals.ts @@ -1,20 +1,3 @@ -/** - * Gecko globals. - */ -declare global { - const Cc: nsXPCComponents_Classes; - const Ci: nsIXPCComponents_Interfaces; - const Cr: nsIXPCComponents_Results; - const Components: nsIXPCComponents; - - // Resolve typed generic overloads before the generated ones. - const Cu: nsXPCComponents_Utils & nsIXPCComponents_Utils; - - const Glean: GleanImpl; - const GleanPings: GleanPingsImpl; - const Services: JSServices; - const uneval: (any) => string; -} // Exports for all modules redirected here by a catch-all rule in tsconfig.json. export var diff --git a/toolkit/jsconfig.json b/toolkit/jsconfig.json new file mode 100644 index 000000000000..ceb95a74b8a4 --- /dev/null +++ b/toolkit/jsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../tools/@types/tsconfig.json", + "include": ["**/*.sys.mjs"] +} diff --git a/toolkit/moz.build b/toolkit/moz.build index e60f9c586bf3..fa9afa2e449b 100644 --- a/toolkit/moz.build +++ b/toolkit/moz.build @@ -94,6 +94,9 @@ with Files("mozapps/preferences/**"): with Files("l10n-registry.manifest"): BUG_COMPONENT = ("Core", "Localization") +with Files("jsconfig.json"): + BUG_COMPONENT = ("Developer Infrastructure", "Lint and Formatting") + GeneratedFile( "content/neterror/aboutNetErrorCodes.js", script="content/neterror/gen_aboutneterror_codes.py", diff --git a/tools/@types/index.d.ts b/tools/@types/index.d.ts index f796d64bf002..e1fc1c11e8c7 100644 --- a/tools/@types/index.d.ts +++ b/tools/@types/index.d.ts @@ -7,3 +7,21 @@ /// /// /// + +/// Order of references matters here, for overriding type signatures. +/// + +declare global { + const Cc: nsXPCComponents_Classes; + const Ci: nsIXPCComponents_Interfaces; + const Components: nsIXPCComponents; + const Cr: nsIXPCComponents_Results; + + // Resolve typed generic overloads before the generated ones. + const Cu: nsXPCComponents_Utils & nsIXPCComponents_Utils; + + const Services: JSServices; + const uneval: (any) => string; +} + +export {}; diff --git a/toolkit/components/extensions/types/gecko.ts b/tools/@types/lib.gecko.tweaks.d.ts similarity index 94% rename from toolkit/components/extensions/types/gecko.ts rename to tools/@types/lib.gecko.tweaks.d.ts index 720919d794d0..01e63a405ee9 100644 --- a/toolkit/components/extensions/types/gecko.ts +++ b/tools/@types/lib.gecko.tweaks.d.ts @@ -91,4 +91,7 @@ interface XULBrowserElement extends XULFrameElement, FrameLoader { remoteType: string; } -type nsQIResult = import("gecko/lib.gecko.xpcom").nsQIResult; +// https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/1736 +interface Localization { + formatValuesSync(aKeys: L10nKey[]): (string | null)[]; +} diff --git a/tools/@types/tsconfig.json b/tools/@types/tsconfig.json new file mode 100644 index 000000000000..b39e1e0ea9aa --- /dev/null +++ b/tools/@types/tsconfig.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "noEmit": true, + "target": "es2022", + "types": ["gecko"] + } +} diff --git a/tools/moz.build b/tools/moz.build index 041c99880086..eacddf0879b2 100644 --- a/tools/moz.build +++ b/tools/moz.build @@ -41,6 +41,9 @@ with Files("tryselect/**"): with Files("tryselect/selectors/release.py"): BUG_COMPONENT = ("Release Engineering", "General") +with Files("ts/**"): + BUG_COMPONENT = ("Developer Infrastructure", "Lint and Formatting") + with Files("update-packaging/**"): BUG_COMPONENT = ("Release Engineering", "General")