Bun

指南运行时

安装 Bun 的 TypeScript 声明

要为 Bun 的内置 API 在你的项目中安装 TypeScript 声明,请安装 @types/bun

bun add -d @types/bun # dev dependency

以下是 Bun 项目推荐的完整 compilerOptions。使用此 tsconfig.json,你可以使用顶层 await、带扩展名或不带扩展名的导入以及 JSX。

{
  "compilerOptions": {
    // Environment setup & latest features
    "lib": ["ESNext"],
    "target": "ESNext",
    "module": "Preserve",
    "moduleDetection": "force",
    "jsx": "react-jsx",
    "allowJs": true,

    // Bundler mode
    "moduleResolution": "bundler",
    "allowImportingTsExtensions": true,
    "verbatimModuleSyntax": true,
    "noEmit": true,

    // Best practices
    "strict": true,
    "skipLibCheck": true,
    "noFallthroughCasesInSwitch": true,
    "noUncheckedIndexedAccess": true,
    "noImplicitOverride": true,

    // Some stricter flags (disabled by default)
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "noPropertyAccessFromIndexSignature": false,
  },
}

请参阅 生态系统 > TypeScript 以获取 Bun 中 TypeScript 支持的完整指南。