您如何让 Typescript 知道您正在 HTML 中的 <scripts> 之间共享数据?

How can you let Typescript know you're sharing data across <scripts> in HTML?

我专门使用 Firebase,但这是适用于任何多脚本用例的一般性问题。

基本上我在一个脚本中声明 const firebaseConfig = { ... };,然后在我的 React 代码中引用该变量,这些文件在经历捆绑过程的单独文件中。

当然,VS Code 会说“嘿,firebaseConfig 不存在!错误!错误!”但事实上确实如此。

我该如何解决这个问题,以免在开发过程中出现误导性错误?

对于 Typescript,只需使用:

declare global {
   const firebaseConfig: any; // or give it a proper type, up to you
}