症状
在改动 tsconfig 或新增 export 后出现 error TS1208: Cannot find global type。它会阻断代码显然在使用的类型解析。
诊断
找出缺失的全局类型及其声明来源:
{ "compilerOptions": { "target": "ES2020", "lib": ["ES2020", "DOM"], "types": [] } }
// globals.d.ts — must stay ambient (no import/export)
declare const BUILD_ID: string;
修复
设置 lib/target,并让声明文件保持 ambient:
{ "compilerOptions": { "lib": ["ES2022", "DOM"], "types": ["node"] } }
若声明需要 import,则将其改为模块并显式导入类型。
验证
重新运行 tsc;TS1208 消失且全局类型可解析,确认声明已回到程序作用域,且 lib 覆盖了所用全局。