# TypeScript (/runtime/typescript)

<!-- agent-signals: reading_time_min: 1 · est_tokens: 370 · updated: 2026-07-28 -->

Install `@types/bun` to get TypeScript definitions for Bun's built-in APIs.

```sh
bun add -d @types/bun # dev dependency
```

You can now reference the `Bun` global in your TypeScript files without seeing errors in your editor.

```ts
console.log(Bun.version);
```

## Suggested `compilerOptions` [#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.

```jsonc
{
  "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.)

```sh
bun init
```
