使用“declare global”操作即可。
项目根目录下新建myDeclareFile.d.ts
declare global { ?interface Navigator { ???mediaSession: any ?} ?interface String { ???myExtendAction: () => void ?} ?const myVariable = 1}
typescript 定义全局变量以及扩展原生js对象
原文地址:https://www.cnblogs.com/axel10/p/10234008.html