若要安裝專案中 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 支援的完整指南。