以chrome插件为例,当开发插件时使用 DefinitelyTyped 中的 chrome 类型定义
- 在这个地方搜索所需的第三方类型声明
- yarn add @types/chrome -D 安装到 devDependencies 中
- 查看 node_modules/@types 中有没有chrome,有的话就可以在全局用了
- 需要在 .eslintrc.js 中添加 chrome 全局定义
module.exports = {
globals: {
chrome: 'readonly',
},
}
具体参考 ESlint 官方声明
- 类型可以按照下方示例 chrome.cookies.Cookie[] 直接使用
chrome.cookies.getAll(
{url: url, name: name},
(result: chrome.cookies.Cookie[]) => {}
);