GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

No menu could be recovered. Follow the blue links in the page.

This view

  • Original page
  • New address

GeezerVison is showing bun-docs.vercel.app — TypeScript | Bun Docs

Get Started

Welcome to BunInstallationQuickstartTypeScriptTypeScript 6 and 7bun initbun create

Core Runtime

Bun RuntimeWatch ModeDebuggingREPLbunfig.toml

File & Module System

File TypesModule ResolutionJSXAuto-installPluginsFile System Router

HTTP Server

ServerRoutingCookiesTLSError HandlingMetricsWebSockets

Networking

FetchTCPUDPDNS

Data & Storage

CookiesFile I/OStreamsBinary DataArchiveSQLSQLiteS3Redis

Concurrency

Workers

Process & System

Environment VariablesShellSpawnWebViewCron

Interop & Tooling

Node-APIFFIC CompilerTranspiler

Utilities

CSRF ProtectionSecretsConsoleMarkdownTOMLYAMLJSON5JSONLXMLHTMLRewriterImageHashingGlobSemverColorUtils

Standards & Compatibility

GlobalsBun APIsWeb APIsNode.js Compatibility

Contributing

RoadmapBenchmarkingContributingBuilding WindowsBindgenLicense
Runtime
Bundler
Package Manager
Test Runner
Guides
Reference
Blog
Install Bun
Runtime Get Started

TypeScript

Using TypeScript with Bun, including type definitions and compiler options

Using TypeScript with Bun, including type definitions and compiler options

To get TypeScript definitions for Bun's built-in APIs, install @types/bun.

terminal
$ bun add -d @types/bun  # dev dependency

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

Suggested compilerOptions

Bun supports top-level await, JSX, and imports with .ts extensions, which TypeScript doesn't allow by default. Use these compilerOptions in a Bun project so TypeScript doesn't warn about those features.

tsconfig.json
{
  "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.

terminal
$ bun init

TypeScript 6 and 7

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

Quickstart

Build your first app with Bun

TypeScript 6 and 7

How to configure Bun's type definitions for TypeScript 6.0 and 7.0, which no longer auto-discover @types packages. Fix 'Cannot find name Bun' and other missing type errors after upgrading TypeScript.

On this page

Suggested compilerOptions
TypeScript 6 and 7
Feedback
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.