aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Colin McDonnell <colinmcd94@gmail.com> 2023-09-20 17:41:26 -0700
committerGravatar Colin McDonnell <colinmcd94@gmail.com> 2023-09-21 12:35:41 -0700
commit66cdb077ad1ecfa4ba6b8e79640110a4822b6d28 (patch)
treed2b50507d0f345593cba0e8dd3a3475271fe9ac6
parent4a1573e007f984a9c1eb11a5fa003f73e84dc975 (diff)
downloadbun-66cdb077ad1ecfa4ba6b8e79640110a4822b6d28.tar.gz
bun-66cdb077ad1ecfa4ba6b8e79640110a4822b6d28.tar.zst
bun-66cdb077ad1ecfa4ba6b8e79640110a4822b6d28.zip
Add docs for extending process.env
-rw-r--r--docs/runtime/env.md25
1 files changed, 25 insertions, 0 deletions
diff --git a/docs/runtime/env.md b/docs/runtime/env.md
index 593590fd0..7fcfd98aa 100644
--- a/docs/runtime/env.md
+++ b/docs/runtime/env.md
@@ -52,6 +52,31 @@ FOOBAR=aaaaaa
<lots more lines>
```
+## TypeScript
+
+In TypeScript, all properties of `process.env` are typed as `string | undefined`.
+
+```ts
+Bun.env.whatever;
+// string | undefined
+```
+
+To get autocompletion and tell TypeScript to treat a variable as a non-optional string, we'll use [interface merging](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#merging-interfaces).
+
+```ts
+declare module "bun" {
+ interface Env {
+ AWESOME: string;
+ }
+}
+```
+
+Add this line to any file in your project. It will globally add the `AWESOME` property to `process.env` and `Bun.env`.
+
+```ts
+process.env.AWESOME; // => string
+```
+
## Configuring Bun
These environment variables are read by Bun and configure aspects of its behavior.