admin管理员组文章数量:1290306
I am creating a WebExtension using TypeScript which is later piled to JavaScript.
My extension depends on one of the APIs the browser (Firefox) offers, specifically the extension API. As an example, I use the getURL() method, which is called like this:
browser.extension.getURL("foo/bar.js");
Of course, TypeScript gives an error "Cannot find name 'browser'". This prevents me from fully piling the code. I would like to know if there is any way to bypass this. Preferably not only at pile level, but also at the linting level.
I have tried:
- Defining
browser
at the beginning asvar browser: any;
: breaks the API. - Compiling with
--noEmit
,--noEmitOnErrors
: irrelevant, still plains.
Any suggestions?
I am creating a WebExtension using TypeScript which is later piled to JavaScript.
My extension depends on one of the APIs the browser (Firefox) offers, specifically the extension API. As an example, I use the getURL() method, which is called like this:
browser.extension.getURL("foo/bar.js");
Of course, TypeScript gives an error "Cannot find name 'browser'". This prevents me from fully piling the code. I would like to know if there is any way to bypass this. Preferably not only at pile level, but also at the linting level.
I have tried:
- Defining
browser
at the beginning asvar browser: any;
: breaks the API. - Compiling with
--noEmit
,--noEmitOnErrors
: irrelevant, still plains.
Any suggestions?
Share Improve this question asked Jul 26, 2018 at 11:34 user8774937user8774937 1831 silver badge7 bronze badges 2- You can also try browser['extension']['getURL']("foo/bar.js"); – Shivam Muttoo Commented Jul 26, 2018 at 11:38
-
@mpm Apparently a
var
betweendeclare
andbrowser
is needed, as @TitianCernicova-Dragomir said. Thank you anyway :) – user8774937 Commented Jul 26, 2018 at 11:41
1 Answer
Reset to default 12If you want to let Typescript know that the variable exists but not actually emit any code for it you can use declare
declare var browser: any;
本文标签: javascriptIgnore not declared variables (TypeScript)Stack Overflow
版权声明:本文标题:javascript - Ignore not declared variables (TypeScript) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741498261a2381934.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论