VS Code 中的 Bun:使用 Bun 单例时出现错误“Cannot find name Bun”

ter*_*uad 5 typescript visual-studio-code windows-subsystem-for-linux bun

我遇到的问题

我在 WSL 中安装了Bun并通过 VS Code 连接到它,但是当我尝试Bun.serve在代码中使用时,VS Code 显示错误,指出Cannot find name 'Bun'. 我知道这是因为 VS Code 不知道我正在使用 Bun,但我不知道如何让 VS Code 识别 Bun。

我尝试过的

我尝试安装官方的 Bun VS Code 扩展,但错误仍然存​​在。我也在谷歌上搜索过,但没有找到任何东西。

我所期待的

错误应该停止显示,理想情况下 VS Code 应该为Bun单例提供自动完成功能。

小智 4

你尝试过这个吗:

在 TS 上,您需要将 Bun-types 安装为 devDependency。

命令:

bun add -d bun-types
Run Code Online (Sandbox Code Playgroud)

tsconfig.json 文件:

{
        "compilerOptions": {
            "types": [
                "bun-types"
            ]
        }
}
Run Code Online (Sandbox Code Playgroud)

请遵循此文档: https: //bun.sh/docs/runtime/typescript