Skip to main content

Install TypeScript declarations for Bun

还没翻译译自英文(bun.com)本页 6 段都还没译

To add TypeScript definitions for Bun's built-in APIs to your project, install @types/bun.

bun add -d @types/bun # dev dependency

Here is the full set of recommended compilerOptions for a Bun project. With this tsconfig.json, you can use top-level await, extensioned or extensionless imports, and JSX.

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

    // 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
  }
}

If you're using TypeScript 6.0 or later, you also need "types": ["bun"] in your compilerOptions. See TypeScript 6 and 7 for details.


To type check your project, run bun check.

bun check

See TypeScript.

翻訳 © 2026 fanyi.dev · 原文 © 2026 the Bun project (LICENSE.md names no copyright holder) (MIT)