You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improve YAML documentation with Bun.YAML.stringify and TypeScript typing
- Add comprehensive Bun.YAML.stringify() documentation with examples
- Explain spacing parameter (null, 2) for readable format vs (null, 0) for condensed
- Document how YAML can represent shared values more compactly than JSON
- Add practical example for generating YAML configuration files
- Clarify TypeScript typing requirements (unlike JSON, not automatic)
- Add both per-file (.d.ts) and global type declaration approaches
- Include Bun.YAML.stringify(obj, null, 2) in examples like JSON.stringify
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
To add TypeScript support for your YAML imports, create a declaration file with `.d.ts` appended to the YAML filename (e.g., `config.yaml` → `config.yaml.d.ts`);
80
+
Unlike JSON files which TypeScript handles automatically, YAML files require manual type definitions. You have two options for adding TypeScript support:
81
+
82
+
### Option 1: Per-File Declaration (Recommended)
83
+
84
+
Create a declaration file with `.d.ts` appended to the YAML filename (e.g., `config.yaml` → `config.yaml.d.ts`):
This approach gives you precise types for each YAML file.
107
+
108
+
### Option 2: Global Declaration
109
+
110
+
For a global type definition (applies to all `.yaml` and `.yml` files), create a declaration file anywhere in your project:
111
+
112
+
```ts global.d.ts icon="/icons/typescript.svg"
113
+
declaremodule"*.yaml" {
114
+
const content:any;
115
+
exportdefaultcontent;
116
+
}
117
+
118
+
declaremodule"*.yml" {
119
+
const content:any;
120
+
exportdefaultcontent;
121
+
}
122
+
```
123
+
124
+
**Note:** TypeScript doesn't automatically type YAML imports like it does for JSON. You must explicitly add type definitions using one of the methods above.
125
+
102
126
---
103
127
104
128
See [Docs > API > YAML](https://bun.com/docs/api/yaml) for complete documentation on YAML support in Bun.
With `space:0`, YAML uses inline notation for arrays and objects where appropriate, making the output more compact than equivalent JSON. This is particularly useful when YAML detects shared/repeated values in your data structure.
80
+
26
81
```ts
27
82
import { YAML } from"bun";
28
83
consttext=`
@@ -435,6 +490,49 @@ if (parseConfig(migrations).autoRun === "true") {
435
490
}
436
491
```
437
492
493
+
### Generating YAML Files
494
+
495
+
You can use `Bun.YAML.stringify()` to programmatically create YAML configuration files:
0 commit comments