bun-types
Version:
Type definitions and documentation for Bun, an incredibly fast JavaScript runtime
55 lines (43 loc) • 1.64 kB
text/mdx
---
title: TypeScript
description: Using TypeScript with Bun, including type definitions and compiler options
---
To install the TypeScript definitions for Bun's built-in APIs, install `/bun`.
```zsh terminal icon="terminal"
bun add -d /bun # dev dependency
```
At this point, you should be able to reference the `Bun` global in your TypeScript files without seeing errors in your editor.
## Suggested `compilerOptions`
Bun supports things like top-level await, JSX, and extensioned `.ts` imports, which TypeScript doesn't allow by default. Below is a set of recommended `compilerOptions` for a Bun project, so you can use these features without seeing compiler warnings from TypeScript.
```json tsconfig.json icon="file-json"
{
"compilerOptions": {
// Environment setup & latest features
"lib": ["ESNext"],
"target": "ESNext",
"module": "Preserve",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,
// 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
}
}
```
If you run `bun init` in a new directory, this `tsconfig.json` will be generated for you. (The stricter flags are disabled by default.)
```sh terminal icon="terminal"
bun init
```