Skip to main content
Bun’s runtime includes a built-in TypeScript transpiler. When you run a .ts or .tsx file, Bun strips the types on the fly and executes the resulting JavaScript — all in the same process, with no intermediate files written to disk.
bun run index.ts      # works, no tsc or ts-node needed
bun run index.tsx     # JSX is supported too
Bun transpiles TypeScript but does not type-check it. Type errors in your editor will not prevent execution. Use bunx tsc --noEmit (see below) to run type checking separately.

Install type definitions

To get Bun.* globals and module types in your editor, install the @types/bun package:
bun add -d @types/bun
After this, you can reference Bun.serve, Bun.file, and all other Bun APIs in TypeScript without seeing “Cannot find name ‘Bun’” errors. If you initialized your project with bun init, @types/bun is already installed and configured. Bun supports features that TypeScript’s default settings don’t allow — top-level await, importing .ts files by extension, and more. The following tsconfig.json is recommended for Bun projects:
tsconfig.json
{
  "compilerOptions": {
    // Environment setup
    "lib": ["ESNext"],
    "target": "ESNext",
    "module": "Preserve",
    "moduleDetection": "force",
    "jsx": "react-jsx",
    "allowJs": true,
    "types": ["bun"],

    // Bundler mode (matches how Bun resolves modules)
    "moduleResolution": "bundler",
    "allowImportingTsExtensions": true,
    "verbatimModuleSyntax": true,
    "noEmit": true,

    // Best practices
    "strict": true,
    "skipLibCheck": true,
    "noFallthroughCasesInSwitch": true,
    "noUncheckedIndexedAccess": true,
    "noImplicitOverride": true
  }
}
bun init generates this file automatically. The key settings are:
SettingWhy
"module": "Preserve"Tells TypeScript not to transform import/export syntax, since Bun handles that.
"moduleResolution": "bundler"Matches Bun’s resolution algorithm, which allows importing .ts files directly.
"allowImportingTsExtensions": trueLets you write import { foo } from "./foo.ts" without TypeScript complaining.
"verbatimModuleSyntax": trueEnsures import type is used for type-only imports, which is required with noEmit.
"noEmit": trueBun handles execution; TypeScript should only be used for type checking.
"types": ["bun"]Loads Bun’s global type declarations from @types/bun.

Type checking

Bun does not type-check your code at runtime. To catch type errors, run the TypeScript compiler in check-only mode using bunx:
bunx tsc --noEmit
bunx downloads and runs typescript from npm without permanently installing it. If you already have TypeScript installed as a dev dependency, you can use it directly:
bun run tsc --noEmit
You can add this as a package.json script and run it in CI:
package.json
{
  "scripts": {
    "typecheck": "tsc --noEmit"
  }
}
bun run typecheck

Path aliases

Bun reads paths from your tsconfig.json and uses them for module resolution. This means path aliases you configure for TypeScript also work at runtime — no separate bundler config needed.
tsconfig.json
{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@utils/*": ["src/utils/*"],
      "@components/*": ["src/components/*"]
    }
  }
}
With this config, the following import resolves to src/utils/format.ts at runtime:
import { formatDate } from "@utils/format";

JSX

Bun supports .jsx and .tsx files out of the box using the same transpiler. The JSX transform is controlled by the "jsx" field in tsconfig.json.
tsconfig.json
{
  "compilerOptions": {
    "jsx": "react-jsx"  // uses the automatic runtime (React 17+)
  }
}
To use a different JSX runtime (such as Preact or Solid), set "jsxImportSource":
tsconfig.json
{
  "compilerOptions": {
    "jsx": "react-jsx",
    "jsxImportSource": "preact"
  }
}
No Babel or other transform tools are required. Bun handles all of this natively.

TypeScript 6 and later

TypeScript 6.0 changed how @types/* packages are loaded. If you are using TypeScript 6.0 or later, explicitly include "types": ["bun"] in your compilerOptions to ensure Bun’s global declarations are loaded:
tsconfig.json
{
  "compilerOptions": {
    "types": ["bun"]
  }
}

Build docs developers (and LLMs) love