Skip to main content
Install @types/bun to get TypeScript definitions for Bun’s built-in APIs.
bun add -d @types/bun # dev dependency
You can now reference the Bun global in your TypeScript files without seeing errors in your editor.
console.log(Bun.version);

Suggested compilerOptions

Bun supports top-level await, JSX, and imports with .ts extensions, which TypeScript doesn’t allow by default. The following compilerOptions are recommended for a Bun project, so you can use these features without compiler warnings from TypeScript.
{
  "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,
  },
}
Running bun init in a new directory generates this tsconfig.json for you. (The stricter flags are disabled by default.)
bun init