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 Bun.YAML.stringify() documentation with examples using (null, 2) for spacing
- Document space parameter: 2 for readable format, 0 for condensed inline notation
- Add TypeScript section in Module Import explaining manual .d.ts requirement
- Clarify that unlike JSON, TypeScript doesn't automatically type YAML imports
🤖 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.
Unlike JSON files, TypeScript doesn't automatically type YAML imports. Add type definitions by creating a `.d.ts` file with the same name as your YAML file:
240
+
241
+
```tsconfig.yaml.d.tsicon="/icons/typescript.svg"
242
+
constcontents: {
243
+
database: {
244
+
host: string;
245
+
port: number;
246
+
name: string;
247
+
};
248
+
server: {
249
+
port: number;
250
+
timeout: number;
251
+
};
252
+
features: {
253
+
auth: boolean;
254
+
rateLimit: boolean;
255
+
};
256
+
};
257
+
258
+
export=contents;
259
+
```
260
+
196
261
---
197
262
198
263
## Hot Reloading with YAML
@@ -435,6 +500,49 @@ if (parseConfig(migrations).autoRun === "true") {
435
500
}
436
501
```
437
502
503
+
### Generating YAML Files
504
+
505
+
You can use `Bun.YAML.stringify()` to programmatically create YAML configuration files:
0 commit comments