aboutsummaryrefslogtreecommitdiff
path: root/docs/guides/runtime
diff options
context:
space:
mode:
authorGravatar Colin McDonnell <colinmcd94@gmail.com> 2023-09-13 20:43:39 -0700
committerGravatar GitHub <noreply@github.com> 2023-09-13 20:43:39 -0700
commitc99caccdb2e1bb961b13766ec7ebb9907763e364 (patch)
treecbc65806656c2b2765666e96a168f5613adf9bb4 /docs/guides/runtime
parent22f14129e5f8e0328b200ce3a8573dbd7c9562c4 (diff)
downloadbun-c99caccdb2e1bb961b13766ec7ebb9907763e364.tar.gz
bun-c99caccdb2e1bb961b13766ec7ebb9907763e364.tar.zst
bun-c99caccdb2e1bb961b13766ec7ebb9907763e364.zip
More docs & helptext cleanup (#5229)
* wip * Flesh out resolution docs * Polish * More * WIP * WIP * WIP * Document --watch
Diffstat (limited to 'docs/guides/runtime')
-rw-r--r--docs/guides/runtime/typescript.md69
1 files changed, 69 insertions, 0 deletions
diff --git a/docs/guides/runtime/typescript.md b/docs/guides/runtime/typescript.md
new file mode 100644
index 000000000..f6afe02c1
--- /dev/null
+++ b/docs/guides/runtime/typescript.md
@@ -0,0 +1,69 @@
+---
+name: Install TypeScript declarations for Bun
+---
+
+To install TypeScript definitions for Bun's built-in APIs in your project, install `bun-types`.
+
+```sh
+$ bun add -d bun-types # dev dependency
+```
+
+---
+
+Then include `"bun-types"` in the `compilerOptions.types` in your `tsconfig.json`:
+
+```json-diff
+ {
+ "compilerOptions": {
++ "types": ["bun-types"]
+ }
+ }
+```
+
+---
+
+Unfortunately, setting a value for `"types"` means that TypeScript will ignore other global type definitions, including `lib: ["dom"]`. If you need to add DOM types into your project, add the following [triple-slash directives](https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html) at the top of any TypeScript file in your project.
+
+```ts
+/// <reference lib="dom" />
+/// <reference lib="dom.iterable" />
+```
+
+---
+
+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.
+
+```jsonc
+{
+ "compilerOptions": {
+ // add Bun type definitions
+ "types": ["bun-types"],
+
+ // enable latest features
+ "lib": ["esnext"],
+ "module": "esnext",
+ "target": "esnext",
+
+ // if TS 5.x+
+ "moduleResolution": "bundler",
+ "noEmit": true,
+ "allowImportingTsExtensions": true,
+ "moduleDetection": "force",
+ // if TS 4.x or earlier
+ // "moduleResolution": "nodenext",
+
+ "jsx": "react-jsx", // support JSX
+ "allowJs": true, // allow importing `.js` from `.ts`
+ "esModuleInterop": true, // allow default imports for CommonJS modules
+
+ // best practices
+ "strict": true,
+ "forceConsistentCasingInFileNames": true,
+ "skipLibCheck": true
+ }
+}
+```
+
+---
+
+Refer to [Ecosystem > TypeScript](/docs/runtime/typescript) for a complete guide to TypeScript support in Bun.