Bun、Request 或来自 @types/bun 的其他全局变量,以下是修复方法。
变化内容
从 TypeScript 6.0 开始,compilerOptions 中的 types 字段默认变为空数组,而不是包含所有的 @types/* 包。现在你需要显式列出你使用的类型包。
在 tsconfig 中添加 "types": ["bun"]
在你的 tsconfig.json 中,向 compilerOptions 添加 "types": ["bun"]:
tsconfig.json
@types/bun 加载类型定义。如果你使用其他 @types/* 包,也请一并包含:
tsconfig.json
@types/bun —— types 选项告诉 TypeScript 要包含哪些包,但包本身必须存在于 node_modules 中:
terminal
完整的推荐 tsconfig.json
以下是针对使用 TypeScript 6.0 或更高版本的 Bun 项目的完整推荐tsconfig.json:
tsconfig.json
这是否适用于 TypeScript 7?
是的。TypeScript 7 延续了相同的默认行为。如果你直接从 TypeScript 5 升级到 7,同样的修复方法适用——向你的compilerOptions 添加 "types": ["bun"]。