diff --git a/.eslintrc-ignores.js b/.eslintrc-ignores.js index 2f554fec938a..a0c27845a248 100644 --- a/.eslintrc-ignores.js +++ b/.eslintrc-ignores.js @@ -24,6 +24,9 @@ module.exports = [ // Include all js dot files. "!.*.js", + // Exclude TypeScript files. + "*.ts", + // Ignore VSCode files ".vscode/", diff --git a/.prettierignore b/.prettierignore index d3647d687c64..9dd50d783108 100644 --- a/.prettierignore +++ b/.prettierignore @@ -7,6 +7,10 @@ !*.sjs !*.xhtml !*.html +!*.ts + +# Prettier currently fails to parse this. +toolkit/components/extensions/types/ext-tabs-base.d.ts # Exclude xhtml/html test files. **/test*/**/*.xhtml @@ -18,9 +22,6 @@ !toolkit/content/tests/chrome/test_preferencesBindings_setting.html !browser/components/preferences/tests/chrome/*.html -# Include Code Connect figma files -!toolkit/content/widgets/**/*.figma.ts - # This should be re-enabled in bug 1827456. js/src/builtin @@ -1108,6 +1109,9 @@ dom/encoding/test/file_utf16_le_bom.js dom/base/test/file_js_cache.js dom/serviceworkers/test/file_js_cache.js +# .ts files that aren't TypeScript +dom/media/test/hls/*.ts + # Intentional broken files dom/base/test/file_js_cache_syntax_error.js dom/base/test/jsmodules/test_scriptNotParsedAsModule.html @@ -1698,5 +1702,6 @@ tools/@types/subs/ tools/browsertime/package.json tools/browsertime/package-lock.json tools/ts/error_list.json +tools/ts/test/baselines/ try_task_config.json xpcom/idl-parser/xpidl/fixtures/xpctest.d.json diff --git a/devtools/client/performance-new/@types/gecko.d.ts b/devtools/client/performance-new/@types/gecko.d.ts index 86795044c1e2..8945cd1f9314 100644 --- a/devtools/client/performance-new/@types/gecko.d.ts +++ b/devtools/client/performance-new/@types/gecko.d.ts @@ -245,7 +245,7 @@ declare namespace MockedExports { preferredWidth?: number ) => Promise; // TS-TODO: Add the rest. - }, + }; toURI: (uri: string | URL | nsIURI) => nsIURI; }; }; diff --git a/taskcluster/kinds/source-test/mozlint.yml b/taskcluster/kinds/source-test/mozlint.yml index 5666ecd84bc6..a07bc14518f1 100644 --- a/taskcluster/kinds/source-test/mozlint.yml +++ b/taskcluster/kinds/source-test/mozlint.yml @@ -109,7 +109,7 @@ eslint: - '**/*.sjs' - '**/*.html' - '**/*.xhtml' - - '**/*.xml' + - '**/*.ts' - 'tools/lint/eslint.yml' # Run when eslint or prettier policies change. - '**/*eslintrc*' @@ -551,6 +551,7 @@ file-perm: - '**/*.rst' - '**/*.svg' - '**/*.toml' + - '**/*.ts' - '**/*.ttf' - '**/*.wasm' - '**/*.webidl' diff --git a/toolkit/components/extensions/types/extensions.ts b/toolkit/components/extensions/types/extensions.ts index c78860f750f6..29e6fa68c44c 100644 --- a/toolkit/components/extensions/types/extensions.ts +++ b/toolkit/components/extensions/types/extensions.ts @@ -2,13 +2,12 @@ * Types specific to toolkit/extensions code. */ declare global { - type BaseContext = import("ExtensionCommon.sys.mjs").BaseContext; type ExtensionChild = import("ExtensionChild.sys.mjs").ExtensionChild; type Extension = import("Extension.sys.mjs").Extension; type callback = (...any) => any; - interface nsIDOMProcessChild { + interface nsIDOMProcessChild { getActor(name: "ProcessConduits"): ProcessConduitsChild; } @@ -33,4 +32,4 @@ import { PointConduit, ProcessConduitsChild } from "ConduitsChild.sys.mjs"; import { ConduitAddress } from "ConduitsParent.sys.mjs"; type Conduit = PointConduit & { [s in `send${Items}`]: callback }; -type Init = ConduitAddress & { send: Send; }; +type Init = ConduitAddress & { send: Send }; diff --git a/toolkit/components/extensions/types/globals.ts b/toolkit/components/extensions/types/globals.ts index 95fade9bc7f6..4b7aa8ee8de1 100644 --- a/toolkit/components/extensions/types/globals.ts +++ b/toolkit/components/extensions/types/globals.ts @@ -1,10 +1,24 @@ - // Exports for all modules redirected here by a catch-all rule in tsconfig.json. -export var - AddonManager, AddonManagerPrivate, AddonSettings, AddonWrapper, AsyncShutdown, - ExtensionMenus, ExtensionProcessScript, ExtensionScriptingStore, ExtensionUserScripts, - NetUtil, E10SUtils, LightweightThemeManager, ServiceWorkerCleanUp, GeckoViewConnection, - GeckoViewWebExtension, IndexedDB, JSONFile, Log, UrlbarUtils, WebExtensionDescriptorActor; +export var AddonManager, + AddonManagerPrivate, + AddonSettings, + AddonWrapper, + AsyncShutdown, + ExtensionMenus, + ExtensionProcessScript, + ExtensionScriptingStore, + ExtensionUserScripts, + NetUtil, + E10SUtils, + LightweightThemeManager, + ServiceWorkerCleanUp, + GeckoViewConnection, + GeckoViewWebExtension, + IndexedDB, + JSONFile, + Log, + UrlbarUtils, + WebExtensionDescriptorActor; /** * A stub type for the "class" from EventEmitter.sys.mjs. diff --git a/toolkit/components/places/types/globals.ts b/toolkit/components/places/types/globals.ts index c00328268aac..419dee26a5b1 100644 --- a/toolkit/components/places/types/globals.ts +++ b/toolkit/components/places/types/globals.ts @@ -1,9 +1,8 @@ export {}; declare global { - type Extension = import("resource://gre/modules/Extension.sys.mjs").Extension; - type DeferredTask = import("resource://gre/modules/DeferredTask.sys.mjs").DeferredTask; - + type DeferredTask = + import("resource://gre/modules/DeferredTask.sys.mjs").DeferredTask; } diff --git a/toolkit/components/translations/translations.d.ts b/toolkit/components/translations/translations.d.ts index 1ef5f31ad389..babbfa1722c2 100644 --- a/toolkit/components/translations/translations.d.ts +++ b/toolkit/components/translations/translations.d.ts @@ -12,7 +12,7 @@ * For Remote Settings, the JSON details about the attachment. */ export interface Attachment { - // e.g. "2f7c0f7bbc...ca79f0850c4de", + // e.g. "2f7c0f7bbc...ca79f0850c4de", hash: string; // e.g. 5047568, size: string; @@ -183,37 +183,36 @@ export namespace Bergamot { // Whether to include sentenceMappings or not. Alignments require // sentenceMappings and are available irrespective of this option if // `alignment=true`. - sentenceMappings: boolean + sentenceMappings: boolean; } } - /** * The client to interact with RemoteSettings. * See services/settings/RemoteSettingsClient.sys.mjs */ interface RemoteSettingsClient { - on: Function, - get: Function, - attachments: any, + on: Function; + get: Function; + attachments: any; } /** * A single language model file. */ interface LanguageTranslationModelFile { - buffer: ArrayBuffer, - record: TranslationModelRecord, + buffer: ArrayBuffer; + record: TranslationModelRecord; } /** * The data required to construct a Bergamot Translation Model. */ interface TranslationModelPayload { - sourceLanguage: string, - targetLanguage: string, - variant?: string, - languageModelFiles: LanguageTranslationModelFiles, + sourceLanguage: string; + targetLanguage: string; + variant?: string; + languageModelFiles: LanguageTranslationModelFiles; } /** @@ -221,26 +220,26 @@ interface TranslationModelPayload { */ interface LanguageTranslationModelFiles { // The machine learning language model. - model: LanguageTranslationModelFile, + model: LanguageTranslationModelFile; // The lexical shortlist that limits possible output of the decoder and makes // inference faster. - lex?: LanguageTranslationModelFile, + lex?: LanguageTranslationModelFile; // A model that can generate a translation quality estimation. - qualityModel?: LanguageTranslationModelFile, + qualityModel?: LanguageTranslationModelFile; // There is either a single vocab file: - vocab?: LanguageTranslationModelFile, + vocab?: LanguageTranslationModelFile; // Or there are two: - srcvocab?: LanguageTranslationModelFile, - trgvocab?: LanguageTranslationModelFile, + srcvocab?: LanguageTranslationModelFile; + trgvocab?: LanguageTranslationModelFile; } /** * This is the type that is generated when the models are loaded into wasm aligned memory. */ type LanguageTranslationModelFilesAligned = { - [K in keyof LanguageTranslationModelFiles]: Bergamot.AlignedMemory + [K in keyof LanguageTranslationModelFiles]: Bergamot.AlignedMemory; }; /** @@ -249,9 +248,9 @@ type LanguageTranslationModelFilesAligned = { * and so the engine will be mocked. */ interface TranslationsEnginePayload { - bergamotWasmArrayBuffer: ArrayBuffer, - translationModelPayloads: TranslationModelPayload[] - isMocked: boolean, + bergamotWasmArrayBuffer: ArrayBuffer; + translationModelPayloads: TranslationModelPayload[]; + isMocked: boolean; } /** @@ -263,12 +262,12 @@ export type NodeVisibility = "in-viewport" | "out-of-viewport" | "hidden"; * Used to decide how to translate a page for full page translations. */ export interface LangTags { - isDocLangTagSupported: boolean, - docLangTag: string | null, - userLangTag: string | null, - htmlLangAttribute: string | null, - identifiedLangTag: string | null, - identifiedLangConfident?: boolean, + isDocLangTagSupported: boolean; + docLangTag: string | null; + userLangTag: string | null; + htmlLangAttribute: string | null; + identifiedLangTag: string | null; + identifiedLangConfident?: boolean; } /** @@ -276,10 +275,10 @@ export interface LangTags { * should be solvable by picking model variants, and pivoting through English. */ export interface LanguagePair { - sourceLanguage: string, - targetLanguage: string, - sourceVariant?: string, - targetVariant?: string + sourceLanguage: string; + targetLanguage: string; + sourceVariant?: string; + targetVariant?: string; } /** @@ -288,16 +287,16 @@ export interface LanguagePair { * needs and how they are resolved. */ export interface NonPivotLanguagePair { - sourceLanguage: string, - targetLanguage: string, - variant?: string, + sourceLanguage: string; + targetLanguage: string; + variant?: string; } export interface SupportedLanguage { - langTag: string, - langTagKey: string, - variant: string - displayName: string, + langTag: string; + langTagKey: string; + variant: string; + displayName: string; } /** @@ -305,51 +304,99 @@ export interface SupportedLanguage { * for translation language selection. */ export interface SupportedLanguages { - languagePairs: NonPivotLanguagePair[], - sourceLanguages: Array, - targetLanguages: Array, + languagePairs: NonPivotLanguagePair[]; + sourceLanguages: Array; + targetLanguages: Array; } export type TranslationErrors = "engine-load-error"; export type SelectTranslationsPanelState = // The panel is closed. - | { phase: "closed"; } + | { phase: "closed" } // The panel is idle after successful initialization and ready to attempt translation. - | { phase: "idle"; sourceLanguage: string; targetLanguage: string, sourceText: string, } + | { + phase: "idle"; + sourceLanguage: string; + targetLanguage: string; + sourceText: string; + } // The language dropdown menus failed to populate upon opening the panel. // This state contains all of the information for the try-again button to close and re-open the panel. - | { phase: "init-failure"; event: Event, screenX: number, screenY: number, sourceText: string, isTextSelected: boolean, langPairPromise: Promise<{sourceLanguage?: string, targetLanguage?: string}> } + | { + phase: "init-failure"; + event: Event; + screenX: number; + screenY: number; + sourceText: string; + isTextSelected: boolean; + langPairPromise: Promise<{ + sourceLanguage?: string; + targetLanguage?: string; + }>; + } // The translation failed to complete. - | { phase: "translation-failure"; sourceLanguage: string; targetLanguage: string, sourceText: string, } + | { + phase: "translation-failure"; + sourceLanguage: string; + targetLanguage: string; + sourceText: string; + } // The selected language pair is determined to be translatable. - | { phase: "translatable"; sourceLanguage: string; targetLanguage: string, sourceText: string, } + | { + phase: "translatable"; + sourceLanguage: string; + targetLanguage: string; + sourceText: string; + } // The panel is actively translating the source text. - | { phase: "translating"; sourceLanguage: string; targetLanguage: string, sourceText: string, } + | { + phase: "translating"; + sourceLanguage: string; + targetLanguage: string; + sourceText: string; + } // The source text has been translated successfully. - | { phase: "translated"; sourceLanguage: string; targetLanguage: string, sourceText: string, translatedText: string, } + | { + phase: "translated"; + sourceLanguage: string; + targetLanguage: string; + sourceText: string; + translatedText: string; + } // The source language is not currently supported by Translations in Firefox. - | { phase: "unsupported"; detectedLanguage: string; targetLanguage: string, sourceText: string } + | { + phase: "unsupported"; + detectedLanguage: string; + targetLanguage: string; + sourceText: string; + }; -export type RequestTranslationsPort = (languagePair: LanguagePair) => Promise +export type RequestTranslationsPort = ( + languagePair: LanguagePair +) => Promise; export type TranslationsPortMessages = { - type: "TranslationsPort:TranslationRequest", - translationId: string, - sourceText: string, - isHTML: boolean, -} + type: "TranslationsPort:TranslationRequest"; + translationId: string; + sourceText: string; + isHTML: boolean; +}; export type EngineStatus = "uninitialized" | "ready" | "error" | "closed"; export type PortToPage = - | { type: "TranslationsPort:TranslationResponse", targetText: string, translationId: number } - | { type: "TranslationsPort:GetEngineStatusResponse", status: EngineStatus } - | { type: "TranslationsPort:EngineTerminated" } + | { + type: "TranslationsPort:TranslationResponse"; + targetText: string; + translationId: number; + } + | { type: "TranslationsPort:GetEngineStatusResponse"; status: EngineStatus } + | { type: "TranslationsPort:EngineTerminated" }; diff --git a/tools/@types/lib.gecko.custom.d.ts b/tools/@types/lib.gecko.custom.d.ts index 8e2e63635542..5b827d7aaf3d 100644 --- a/tools/@types/lib.gecko.custom.d.ts +++ b/tools/@types/lib.gecko.custom.d.ts @@ -4,31 +4,39 @@ declare global { type DeclaredLazy = { - [P in keyof T]: - T[P] extends (() => infer U) ? U : - T[P] extends keyof LazyModules ? Exports : - T[P] extends { pref: string, default?: infer U } ? Widen : - T[P] extends { service: string, iid?: infer U } ? nsQIResult : - never; - } + [P in keyof T]: T[P] extends () => infer U + ? U + : T[P] extends keyof LazyModules + ? Exports + : T[P] extends { pref: string; default?: infer U } + ? Widen + : T[P] extends { service: string; iid?: infer U } + ? nsQIResult + : never; + }; - type LazyDefinition = Record any) | - { service: string, iid: nsIID } | - { pref: string, default?, onUpdate?, transform? } + type LazyDefinition = Record< + string, + | string + | (() => any) + | { service: string; iid: nsIID } + | { pref: string; default?; onUpdate?; transform? } >; } -type Exports = M extends keyof LazyModules ? IfKey : never; +type Exports = M extends keyof LazyModules + ? IfKey + : never; type IfKey = K extends keyof T ? T[K] : never; type LazyModules = import("./generated/lib.gecko.modules").LazyModules; -type Widen = - T extends boolean ? boolean : - T extends number ? number : - T extends string ? string : - never; +type Widen = T extends boolean + ? boolean + : T extends number + ? number + : T extends string + ? string + : never; export {}; diff --git a/tools/@types/lib.gecko.tweaks.d.ts b/tools/@types/lib.gecko.tweaks.d.ts index 88c3b61e8bed..70dc038622f7 100644 --- a/tools/@types/lib.gecko.tweaks.d.ts +++ b/tools/@types/lib.gecko.tweaks.d.ts @@ -21,17 +21,27 @@ interface Document { } type nsIGleanPingNoReason = { - [K in keyof nsIGleanPing]: K extends "submit" ? (_?: never) => void : nsIGleanPing[K]; -} + [K in keyof nsIGleanPing]: K extends "submit" + ? (_?: never) => void + : nsIGleanPing[K]; +}; type nsIGleanPingWithReason = { - [K in keyof nsIGleanPing]: K extends "submit" ? (reason: T) => void : nsIGleanPing[K]; -} + [K in keyof nsIGleanPing]: K extends "submit" + ? (reason: T) => void + : nsIGleanPing[K]; +}; interface MessageListenerManagerMixin { // Overloads that define `data` arg as required, since it's ~always expected. - addMessageListener(msg: string, listener: { receiveMessage(_: ReceiveMessageArgument & { data })}); - removeMessageListener(msg: string, listener: { receiveMessage(_: ReceiveMessageArgument & { data })}); + addMessageListener( + msg: string, + listener: { receiveMessage(_: ReceiveMessageArgument & { data }) } + ); + removeMessageListener( + msg: string, + listener: { receiveMessage(_: ReceiveMessageArgument & { data }) } + ); } interface MozQueryInterface { @@ -52,16 +62,20 @@ interface nsISupports { } interface nsIXPCComponents_Constructor { - (cid, id: T, init?): { + ( + cid, + id: T, + init? + ): { new (...any): nsQIResult; (...any): nsQIResult; - } + }; } interface ComponentsExceptionOptions { - result?: number, - stack?: nsIStackFrame, - data?: object, + result?: number; + stack?: nsIStackFrame; + data?: object; } interface nsIException extends Exception {} @@ -76,7 +90,7 @@ interface nsIXPCComponents_Exception { } interface nsIXPCComponents_ID { - (uuid: string): nsID + (uuid: string): nsID; } interface nsIXPCComponents_utils_Sandbox { @@ -87,7 +101,7 @@ interface nsXPCComponents_Classes { [cid: string]: { createInstance(aID: T): nsQIResult; getService(aID?: T): unknown extends T ? nsISupports : nsQIResult; - } + }; } // Generic overloads. diff --git a/tools/@types/lib.gecko.xpidl.d.ts b/tools/@types/lib.gecko.xpidl.d.ts index 2bcad68d3955..97e0a04c908b 100644 --- a/tools/@types/lib.gecko.xpidl.d.ts +++ b/tools/@types/lib.gecko.xpidl.d.ts @@ -15,10 +15,12 @@ interface nsID { * and expose constants defined on the class, including variants from enums. * https://searchfox.org/mozilla-central/source/js/xpconnect/src/XPCJSID.cpp#45 */ -type nsJSIID = nsID & Constants & enums & { - new (_: never): void; - prototype: iface; -} +type nsJSIID = nsID & + Constants & + enums & { + new (_: never): void; + prototype: iface; + }; /** A union type of all known interface IIDs. */ type nsIID = nsIXPCComponents_Interfaces[keyof nsIXPCComponents_Interfaces]; diff --git a/tools/lint/eslint.yml b/tools/lint/eslint.yml index a6827cf46221..2489ba9d1ab5 100644 --- a/tools/lint/eslint.yml +++ b/tools/lint/eslint.yml @@ -5,7 +5,7 @@ eslint: include: ['.'] exclude: [] # When adding to this list, consider updating hooks_js_format.py as well. - extensions: ['mjs', 'js', 'json', 'jsx', 'html', 'sjs', 'xhtml'] + extensions: ['mjs', 'js', 'json', 'jsx', 'html', 'sjs', 'xhtml', '.ts'] support-files: - '**/.eslintrc.js' - '.eslintrc*.js' diff --git a/tools/lint/file-perm.yml b/tools/lint/file-perm.yml index cbcb399d4f9c..e4e1d9aabf74 100644 --- a/tools/lint/file-perm.yml +++ b/tools/lint/file-perm.yml @@ -28,6 +28,7 @@ file-perm: - .rst - .svg - .toml + - .ts - .ttf - .wasm - .webidl diff --git a/tools/lint/hooks_js_format.py b/tools/lint/hooks_js_format.py index 8d6ec7552b47..78d1b948a218 100755 --- a/tools/lint/hooks_js_format.py +++ b/tools/lint/hooks_js_format.py @@ -33,7 +33,7 @@ def run_js_format(hooktype, changedFiles): # No files have been touched return - extensions = (".js", ".jsx", ".json", ".mjs", "sjs", "html", "xhtml") + extensions = (".js", ".jsx", ".json", ".mjs", ".sjs", ".html", ".xhtml", ".ts") path_list = [] for filename in sorted(changedFiles): # Ignore files unsupported in eslint and prettier diff --git a/tools/rewriting/Generated.txt b/tools/rewriting/Generated.txt index a2c127007c46..9c664020d7ce 100644 --- a/tools/rewriting/Generated.txt +++ b/tools/rewriting/Generated.txt @@ -224,5 +224,6 @@ tools/@types/subs/ tools/browsertime/package.json tools/browsertime/package-lock.json tools/ts/error_list.json +tools/ts/test/baselines/ try_task_config.json xpcom/idl-parser/xpidl/fixtures/xpctest.d.json