【问题标题】:How can you let Typescript know you're sharing data across <scripts> in HTML?你如何让 Typescript 知道你在 HTML 中跨 <scripts> 共享数据?
【发布时间】:2021-01-15 15:15:31
【问题描述】:

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

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

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

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

【问题讨论】:

    标签: typescript visual-studio-code bundling-and-minification script-tag


    【解决方案1】:

    对于 Typescript,只需使用:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-18
      • 1970-01-01
      • 2012-03-30
      相关资源
      最近更新 更多