Skip to content

global.d.ts

开发浏览器扩展时,injectScript 中难免会用到页面上的方法或变量,比如 window.require,但 TypeScript 无法识别它们。这时需要在 /src/global.d.ts 中声明对应的类型,让 TypeScript 能正确识别。如果你嫌麻烦,可以直接设置为 any 类型。

其他使用例子请查看官方文档 Global .d.ts

typescript
//  src/global.d.ts
export declare global {
  interface Window {
    require: any;
  }
}
//  src/global.d.ts
export declare global {
  interface Window {
    require: any;
  }
}

Powered by Vitepress