问题描述
我专门使用Firebase,但这是一个普遍问题,适用于任何多脚本用例。
基本上,我在一个脚本中声明const firebaseConfig = { ... };
,然后在要进行捆绑过程的单独文件中的React代码中引用该变量。
当然,VS Code会说“嘿,firebaseConfig不存在!错误!错误!”但实际上确实如此。
如何解决这个问题,以免在开发过程中出现误导性错误?
解决方法
对于打字稿,只需使用:
declare global {
const firebaseConfig: any; // or give it a proper type,up to you
}