Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use types without any import statements #107

Open
olfek opened this issue Oct 17, 2024 · 0 comments
Open

Use types without any import statements #107

olfek opened this issue Oct 17, 2024 · 0 comments

Comments

@olfek
Copy link

olfek commented Oct 17, 2024

@types/firefox-webext-browser can be used without any import statements by adding
firefox-webext-browser to tsconfig.json > compilerOptions > types.

When I try to do the same with this package, it does not work.

After some investigation, the cause appears to be the import statements in the index.d.ts file which @types/firefox-webext-browser does not have (import statements).

This workaround (fixes?) the problem:

diff --git "a/webextension-polyfill/index.d.ts" "b/webextension-polyfill/index.d.ts"
index 694e9b6..0dcc4de 100644
--- "a/webextension-polyfill/index.d.ts"
+++ "b/webextension-polyfill/index.d.ts"
@@ -59,7 +59,10 @@ import { WebNavigation as ImportedWebNavigation } from "./namespaces/webNavigati
 import { WebRequest as ImportedWebRequest } from "./namespaces/webRequest";
 import { Windows as ImportedWindows } from "./namespaces/windows";

-declare namespace Browser {
+declare global
+{
+    namespace browser {
         /**
          * Monitor extension activity
          *
@@ -841,6 +844,8 @@ declare namespace Browser {
         export import WebRequest = ImportedWebRequest;
         export import Windows = ImportedWindows;
     }
+}

 // eslint-disable-next-line @definitelytyped/export-just-namespace
-export = Browser;
+export = browser;

Thanks to: https://stackoverflow.com/a/66279933

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant