Description
Hey @cezaraugusto I found @types/firefox-webext-browser
to have inferior types to @types/webextension-polyfill
.
As an example: in https://github.com/DefinitelyTyped/DefinitelyTyped/blob/981449c691b9be0fca569c48151fc57606f5ea7a/types/firefox-webext-browser/index.d.ts#L4680
the func
parameter has a fixed signature of no parameters, although you can (and should) supply args
to a scripting function. Meaning that whenever you use args
, func
incorrectly will report a type error.
Or ExecutionWorld
is hardcoded to ISOLATED.
@types/webextension-polyfill
more correctly types the args as unknown:
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/981449c691b9be0fca569c48151fc57606f5ea7a/types/webextension-polyfill/namespaces/scripting.d.ts#L38
And ExecutionWorld
correctly is type ExecutionWorld = "ISOLATED" | "MAIN"
Which is not insanely good as there could be generics that match args
signature to the func
params signature, but hey at least it doesn't report wrong type errors as @types/firefox-webext-browser
does.
Now the extension.js cli has a dependency on @types/firefox-webext-browser
which ambiently declares itself as a global, which is nice in theory but makes overriding it kinda hard. I was successful with (app/types/browser.d.ts):
/// <reference types="webextension-polyfill" />
declare const browser: typeof import('webextension-polyfill')
So it seemed that your references in extension-env.d.ts
were not enough somehow and I had to do declare const browser
to override firefox-webext-browser
properly. Maybe it has to do with me having the extension in a yarn3 monorepo that hoists to root, but it shouldnt make a difference really as tsconfig is confined to the package-level.
My tsconfig is super simple with no types/typeRoot/include shenanigans:
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"jsx": "react-jsx",
"lib": ["dom", "dom.iterable", "esnext"],
"moduleResolution": "node",
"module": "esnext",
"noEmit": true,
"resolveJsonModule": true,
"strict": true,
"target": "esnext",
"verbatimModuleSyntax": true,
"useDefineForClassFields": true,
"skipLibCheck": true
},
"exclude": ["node_modules", "dist"]
}