.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 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 getBun.* globals and module types in your editor, install the @types/bun package:
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.
Recommended tsconfig.json
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
bun init generates this file automatically. The key settings are:
| Setting | Why |
|---|---|
"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": true | Lets you write import { foo } from "./foo.ts" without TypeScript complaining. |
"verbatimModuleSyntax": true | Ensures import type is used for type-only imports, which is required with noEmit. |
"noEmit": true | Bun 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 usingbunx:
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:
package.json script and run it in CI:
package.json
Path aliases
Bun readspaths 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
src/utils/format.ts at runtime:
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
"jsxImportSource":
tsconfig.json
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