YAML to TypeScript
Paste any YAML document and get ready-to-use TypeScript interface definitions inferred from its structure.
Example
Paste YAML on the left, get TypeScript interfaces on the right.
name: app
version: 3
server:
host: localhost
port: 8080
becomes
interface Root {
name: string;
version: number;
server: Server;
}
interface Server {
host: string;
port: number;
}How it works
It parses your YAML with js-yaml into a value, then walks the value to infer types, naming the root type "Root" and emitting nested interfaces for objects and arrays. Optional keys (null/missing values) are marked with ?.
Good to know
YAML to TypeScript turns a pasted YAML document into ready-to-use TypeScript interface definitions by parsing the data and inferring a type for every value it finds. It is aimed at developers who keep config, fixtures, API responses, or seed data in YAML and want matching types without hand-writing them. The root object becomes an interface named Root, and every nested object or array of objects gets its own named interface so the output stays modular instead of one giant inline type.
Reach for it whenever you have a concrete YAML sample but no schema: typing a Kubernetes-style config block, scaffolding interfaces for a YAML-driven settings file, or quickly stubbing types from an example payload so the compiler can catch typos. Because inference is based on the actual values you paste, the more representative your sample, the more accurate the result, so paste a row that includes every field rather than a stripped-down one.
Read the output top-down: Root is your entry type, and each referenced name (like Server or a singularized array-item name) points to its own interface below. Watch for a few inference signals: a field marked with ? and typed null means the value was null or missing and could not be resolved; unknown[] means an empty array; Record<string, unknown> means an empty object; and a union like (ItemA | ItemB)[] means an array held more than one object shape.
Treat the generated interfaces as a strong first draft, not a final schema. The tool infers from one snapshot, so optional fields that simply weren't present in your sample will be missed, and numeric strings versus numbers depend entirely on how YAML parsed them. Replace any leftover null or unknown types with the real intended type, and add optionality where your data legitimately varies before committing the types to your codebase.
Frequently asked questions
How are optional fields and null values handled?
Keys whose YAML value is null (or missing) are emitted as optional with a ? and typed as null, since the parser cannot infer their real type. Edit them by hand if you know the intended type.
What happens when an array holds mixed item shapes?
Each distinct object shape becomes its own interface and the array is typed as a union, e.g. (ItemA | ItemB)[]. Identical shapes are deduplicated to reuse a single interface.
Is my data uploaded anywhere?
No — this tool runs entirely in your browser. Your input never leaves your device and it works offline once loaded.
Is it free?
Yes, completely free with no sign-up and no limits.
People also ask
Does YAML to TypeScript generate interfaces or type aliases?
It generates interfaces by default, naming the top-level object Root and emitting a separate interface for each nested object. If the root YAML value is a primitive or array rather than an object, it falls back to a type alias such as type Root = string;.
How does it name the interfaces for nested objects and arrays?
Object interface names are derived from the key that holds them, capitalized into PascalCase. For arrays, the item name is singularized from the key (for example a users array yields a User interface), and invalid characters are stripped.
Why is a field typed as string when the YAML value looks like a number?
Types are inferred from how js-yaml parses the value. Quoted values like "3" parse as strings, while unquoted 3 parses as a number, so quoting in your YAML directly affects whether you get string or number.
What type do empty arrays and empty objects produce?
An empty array is typed as unknown[] because there are no items to infer from, and an empty object is typed as Record<string, unknown>. You can refine these manually once you know the real contents.
Does the tool deduplicate identical interfaces?
Yes. If two objects have an identical set of keys and value types, the tool reuses a single interface rather than emitting duplicates, which keeps the output smaller and consistent.
Can I convert TypeScript back into YAML with this tool?
No, this tool is one-directional, going from YAML to TypeScript only. For related YAML tasks you would use separate utilities such as a YAML formatter, validator, or parser.
Is YAML to TypeScript safe to use with private or proprietary config files?
Yes. The conversion runs entirely in your browser using the loaded js-yaml library, so your YAML is never sent to a server and the tool works offline after the page loads.
How are nested objects several levels deep handled?
The tool recursively walks the entire structure, creating a distinct interface at each level of object nesting and linking them by name. Deeply nested data still produces flat, separately named interfaces rather than one deeply inlined type.
Related tools