Bun

指南執行環境

安裝 Bun 的 TypeScript 宣告

若要在您的專案中安裝 Bun 內建 API 的 TypeScript 定義,請安裝 @types/bun

bun add -d @types/bun # dev dependency

以下是 Bun 專案建議的完整 compilerOptions 設定。透過這個 tsconfig.json,您可以使用最上層 await、含副檔名或不含副檔名的匯入,以及 JSX。

{
  "compilerOptions": {
    // Enable latest features
    "lib": ["ESNext", "DOM"],
    "target": "ESNext",
    "module": "ESNext",
    "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,

    // Some stricter flags
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noPropertyAccessFromIndexSignature": true,
  },
}

請參閱生態系統 > TypeScript 以取得 Bun 中 TypeScript 支援的完整指南。