Skip to content

Commit 755e55a

Browse files
authored
🤖 Merge PR DefinitelyTyped#71871 [chrome] Allow using strings in place of chrome.enum.VALUE in offscreen and onInstalled by @fregante
1 parent 7190e99 commit 755e55a

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

‎types/chrome/index.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6584,7 +6584,7 @@ declare namespace chrome {
65846584
/** The parameters describing the offscreen document to create. */
65856585
export interface CreateParameters {
65866586
/** The reason(s) the extension is creating the offscreen document. */
6587-
reasons: Reason[];
6587+
reasons: `${Reason}`[];
65886588
/** The (relative) URL to load in the document. */
65896589
url: string;
65906590
/** A developer-provided string that explains, in more detail, the need for the background context. The user agent _may_ use this in display to the user. */
@@ -8077,7 +8077,7 @@ declare namespace chrome {
80778077
/**
80788078
* The reason that this event is being dispatched.
80798079
*/
8080-
reason: OnInstalledReason;
8080+
reason: `${OnInstalledReason}`;
80818081
/**
80828082
* Optional.
80838083
* Indicates the previous version of the extension, which has just been updated. This is present only if 'reason' is 'update'.

‎types/chrome/test/index.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -967,9 +967,12 @@ function testTtsEngine() {
967967

968968
chrome.runtime.onInstalled.addListener((details) => {
969969
details; // $ExpectType InstalledDetails
970-
details.reason; // $ExpectType OnInstalledReason
971970
details.previousVersion; // $ExpectType string | undefined
971+
details.reason; // $ExpectType "install" | "update" | "chrome_update" | "shared_module_update"
972972
details.id; // $ExpectType string | undefined
973+
if (details.reason === "install") { // Accept string version of enum
974+
return;
975+
}
973976

974977
// @ts-expect-error
975978
details.reason = "not-real-reason";
@@ -2903,7 +2906,10 @@ async function testTopSitesForPromise() {
29032906
// https://developer.chrome.com/docs/extensions/reference/offscreen/
29042907
async function testOffscreenDocument() {
29052908
await chrome.offscreen.createDocument({
2906-
reasons: [chrome.offscreen.Reason.CLIPBOARD],
2909+
reasons: [
2910+
chrome.offscreen.Reason.CLIPBOARD,
2911+
"AUDIO_PLAYBACK", // Accept both enum values and strings
2912+
],
29072913
url: "https://example.com",
29082914
justification: "Example",
29092915
});

0 commit comments

Comments
 (0)