要在項目中為 Bun 的內置 API 安裝 TypeScript 定義,請安裝 @types/bun。
sh
bun add -d @types/bun # 開發依賴以下是 Bun 項目推薦的完整 compilerOptions 集合。使用此 tsconfig.json,你可以使用頂層 await、帶擴展名或無擴展名的導入以及 JSX。
json
{
"compilerOptions": {
// 環境設置和最新功能
"lib": ["ESNext"],
"target": "ESNext",
"module": "Preserve",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,
// 打包器模式
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,
// 最佳實踐
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": true,
"noImplicitOverride": true,
// 一些更嚴格的標志(默認禁用)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false
}
}請參閱 生態系統 > TypeScript 獲取 Bun 中 TypeScript 支持的完整指南。