Compare commits

...

6 Commits

Author SHA1 Message Date
Lydia Hallie
f0fcb96985 Merge branch 'main' into lydia/update-ts-docs 2025-12-01 15:53:13 -06:00
Lydia Hallie
21bfee464a Merge branch 'main' into lydia/update-ts-docs 2025-11-14 13:17:41 -08:00
Lydia Hallie
76a2205898 Merge branch 'main' into lydia/update-ts-docs 2025-11-12 15:45:39 -08:00
Lydia Hallie
a76e8e98c5 Merge branch 'main' into lydia/update-ts-docs 2025-11-12 13:56:53 -08:00
Lydia Hallie
19f81cfad5 format 2025-11-12 13:54:33 -08:00
Lydia Hallie
b06afbccbf Add tsconfig callout 2025-11-12 13:53:19 -08:00
7 changed files with 24 additions and 67 deletions

View File

@@ -102,7 +102,7 @@ bun upgrade --canary
- Runtime
- [`bun run`](https://bun.com/docs/cli/run)
- [File types (Loaders)](https://bun.com/docs/runtime/loaders)
- [TypeScript](https://bun.com/docs/runtime/typescript)
- [TypeScript](https://bun.com/docs/typescript)
- [JSX](https://bun.com/docs/runtime/jsx)
- [Environment variables](https://bun.com/docs/runtime/environment-variables)
- [Bun APIs](https://bun.com/docs/runtime/bun-apis)
@@ -328,7 +328,7 @@ bun upgrade --canary
- [Import a HTML file as text](https://bun.com/guides/runtime/import-html)
- [Install and run Bun in GitHub Actions](https://bun.com/guides/runtime/cicd)
- [Debugging Bun with the web debugger](https://bun.com/guides/runtime/web-debugger)
- [Install TypeScript declarations for Bun](https://bun.com/guides/runtime/typescript)
- [Install TypeScript declarations for Bun](https://bun.com/guides/typescript)
- [Debugging Bun with the VS Code extension](https://bun.com/guides/runtime/vscode-debugger)
- [Inspect memory usage using V8 heap snapshots](https://bun.com/guides/runtime/heap-snapshot)
- [Define and replace static globals & constants](https://bun.com/guides/runtime/define-constant)

View File

@@ -43,4 +43,4 @@ data.author.name; // => "John Dough"
---
See [Docs > Runtime > TypeScript](/runtime/typescript) for more information on using TypeScript with Bun.
See [Docs > TypeScript](/typescript) for more information on using TypeScript with Bun.

View File

@@ -29,4 +29,4 @@ data.author.name; // => "John Dough"
---
See [Docs > Runtime > TypeScript](/runtime/typescript) for more information on using TypeScript with Bun.
See [Docs > TypeScript](/typescript) for more information on using TypeScript with Bun.

View File

@@ -28,4 +28,4 @@ import { Button } from "@components/Button"; // imports from "./src/components/B
---
See [Docs > Runtime > TypeScript](/runtime/typescript) for more information on using TypeScript with Bun.
See [Docs > TypeScript](/typescript) for more information on using TypeScript with Bun.

View File

@@ -10,6 +10,15 @@ To install TypeScript definitions for Bun's built-in APIs in your project, insta
bun add -d @types/bun # dev dependency
```
<Note>
You don't need to manually configure anything in your `tsconfig.json` for Bun's types to work.
Once you install `@types/bun`, TypeScript automatically loads the type definitions for `"bun"`'s modules and the global `Bun` namespace, no extra setup required.
If you ever encounter older guides or projects that mention `bun-types`, that's just a legacy setup. It's not necessary in new Bun projects.
</Note>
---
Below is the full set of recommended `compilerOptions` for a Bun project. With this `tsconfig.json`, you can use top-level await, extensioned or extensionless imports, and JSX.
@@ -45,7 +54,3 @@ Below is the full set of recommended `compilerOptions` for a Bun project. With t
}
}
```
---
Refer to [Ecosystem > TypeScript](/runtime/typescript) for a complete guide to TypeScript support in Bun.

View File

@@ -1,58 +0,0 @@
---
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 `@types/bun`.
```sh
bun add -d @types/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.
```ts
console.log(Bun.version);
```
## 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.
```jsonc
{
"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
bun init
```

View File

@@ -1,6 +1,7 @@
---
title: TypeScript
description: Using TypeScript with Bun, including type definitions and compiler options
mode: center
---
To install the TypeScript definitions for Bun's built-in APIs, install `@types/bun`.
@@ -11,6 +12,15 @@ bun add -d @types/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.
<Note>
You don't need to manually configure anything in your `tsconfig.json` for Bun's types to work.
Once you install `@types/bun`, TypeScript automatically loads the type definitions for `"bun"`'s modules and the global `Bun` namespace, no extra setup required.
If you ever encounter older guides or projects that mention `bun-types`, that's just a legacy setup. It's not necessary in new Bun projects.
</Note>
## 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.