我安装了这个NPM包: https://www.npmjs.com/package/@types/chrome
现在我的代码中有这个:
declare var chrome;
chrome.runtime.onConnect.addListener(function (port) {
console.log('extension is connected to port:', port);
port.onMessage.addListener(function (msg) {
console.log('message from port:', msg);
});
});
当我摆脱声明声明时,我的IDE(Webstorm)没有给出任何关于使用哪种类型的建议。
有谁知道如何在项目中正确引用/合并chrome类型?
答案 0 :(得分:4)
安装chrome定义。
npm install @types/chrome --save-dev
然后,在您的一个打字稿文件中引用它。我是在custom-typings.d.ts
///<reference types="chrome"/>
...