add Bun.YAML.parse to types (#22129)

This commit is contained in:
Dylan Conway
2025-08-25 17:03:25 -07:00
committed by GitHub
parent ec2e2993f5
commit b99bbe7ee4
2 changed files with 32 additions and 0 deletions

View File

@@ -619,6 +619,33 @@ declare module "bun" {
export function parse(input: string): object;
}
/**
* YAML related APIs
*/
namespace YAML {
/**
* Parse a YAML string into a JavaScript value
*
* @category Utilities
*
* @param input The YAML string to parse
* @returns A JavaScript value
*
* @example
* ```ts
* import { YAML } from "bun";
*
* console.log(YAML.parse("123")) // 123
* console.log(YAML.parse("123")) // null
* console.log(YAML.parse("false")) // false
* console.log(YAML.parse("abc")) // "abc"
* console.log(YAML.parse("- abc")) // [ "abc" ]
* console.log(YAML.parse("abc: def")) // { "abc": "def" }
* ```
*/
export function parse(input: string): unknown;
}
/**
* Synchronously resolve a `moduleId` as though it were imported from `parent`
*

View File

@@ -0,0 +1,5 @@
import { expectType } from "./utilities";
expectType(Bun.YAML.parse("")).is<unknown>();
// @ts-expect-error
expectType(Bun.YAML.parse({})).is<unknown>();