From 10c48d2267051d39e60f3d9d45f36d5aca327c1d Mon Sep 17 00:00:00 2001 From: Anjey Tsibylskij <130153594+atldays@users.noreply.github.com> Date: Thu, 5 Nov 2026 22:57:07 +0200 Subject: [PATCH] fix(scripting): avoid the removed chrome Awaited alias Preserve the existing conditional script result type locally so consumers can install newer @types/chrome declarations without TS2694. --- src/api/scripting/methods.ts | 3 ++- tests/consumer-types/scripting-methods-types.ts | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/api/scripting/methods.ts b/src/api/scripting/methods.ts index 2f5e9a4..38c3d88 100644 --- a/src/api/scripting/methods.ts +++ b/src/api/scripting/methods.ts @@ -1,7 +1,8 @@ import {browser} from "../browser"; import {callWithPromise} from "../utils"; -type Awaited = chrome.scripting.Awaited; +// Keep the result type independent of the removed chrome.scripting.Awaited alias. +type Awaited = T extends PromiseLike ? U : T; type ContentScriptFilter = chrome.scripting.ContentScriptFilter; type CSSInjection = chrome.scripting.CSSInjection; type InjectionResult = chrome.scripting.InjectionResult; diff --git a/tests/consumer-types/scripting-methods-types.ts b/tests/consumer-types/scripting-methods-types.ts index ae0da45..320bd57 100644 --- a/tests/consumer-types/scripting-methods-types.ts +++ b/tests/consumer-types/scripting-methods-types.ts @@ -1,6 +1,6 @@ import {executeScript, getRegisteredContentScripts, insertCss, registerContentScripts, removeCss, unregisterContentScripts, updateContentScripts} from "@addon-core/browser"; -type Awaited = chrome.scripting.Awaited; +type Awaited = T extends PromiseLike ? U : T; type ContentScriptFilter = chrome.scripting.ContentScriptFilter; type CSSInjection = chrome.scripting.CSSInjection; type InjectionResult = chrome.scripting.InjectionResult; @@ -20,8 +20,12 @@ type Expected = { }; type Equal = (() => T extends A ? 1 : 2) extends (() => T extends B ? 1 : 2) ? true : false; -const signaturesUnchanged: Equal = true; -void [methods, signaturesUnchanged]; +const signaturesUnchanged: Equal, Omit> = true; +// Conditional result aliases from different declaration files need assignability checks. +const compatibleExecuteScript: Expected["executeScript"] = executeScript; +declare const expectedExecuteScript: Expected["executeScript"]; +const compatibleExpected: typeof executeScript = expectedExecuteScript; +void [methods, signaturesUnchanged, compatibleExecuteScript, compatibleExpected]; const pending: Promise[]> = executeScript>({target: {tabId: 7}, func: async () => 42}); void pending;