Special Sponsor:PromptBuilder— Fast, consistent prompt creation powered by 1,000+ expert templates.
Make your Product visible here.Contact Us
Taking new clients

Need a dev team that ships?

011BQ builds TypeScript-first products, migrations, and internal tools for startups and scale-ups.

  • JS/TS migration & codebase modernisation
  • Custom dev tools & internal platforms
  • React, Next.js & Node.js engineering
  • Code review, architecture & tech advisory

Or reach us directly

011bq.com

Send us a message

We respond within 1 business day.

check_dark

Thank You!

Your message has been successfully sent. We will get back to you soon!

Message sent!

Thanks for reaching out. The 011BQ team will get back to you within 1 business day.

HomeChevronBlogChevronYAML to TypeScript: Complete Guide for Config Files and Kubernetes Manifests

YAML to TypeScript: Complete Guide for Config Files and Kubernetes Manifests

j
js2ts Team
22/05/2026·1 minute 53 seconds read
YAML to TypeScript: Complete Guide for Config Files and Kubernetes ManifestsYAML to TypeScript: Complete Guide for Config Files and Kubernetes Manifests

Why Type YAML in TypeScript?

YAML is everywhere in modern development: Kubernetes configs, Docker Compose, GitHub Actions workflows, Helm values files, application configs. When you read these files in TypeScript, you get any by default — which means no autocomplete, no type checking, and runtime errors when the YAML structure changes.

Typing your YAML configurations gives you compile-time validation, autocomplete when building config files programmatically, and immediate feedback when a config schema changes.

Quick Conversion: Online Tool

For one-off conversions, use our YAML to TypeScript converter. Paste your YAML and get TypeScript interfaces generated automatically — handles nested objects, arrays, optional fields, and all YAML scalar types.

YAML to TypeScript Type Mapping

Understanding the mapping:

# YAML types → TypeScript types
string: "hello"          # → string
number: 42               # → number
float: 3.14              # → number
boolean: true            # → boolean
null: ~                  # → null
array:                   # → T[]
  - item1
  - item2
nested:                  # → nested interface
  key: value

Kubernetes Manifest Types

Here's a Kubernetes Deployment manifest and its TypeScript interface:

# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
  labels:
    app: my-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
        - name: my-app
          image: my-app:latest
          ports:
            - containerPort: 3000
// TypeScript interfaces
export interface KubernetesMetadata {
  name: string;
  labels?: Record<string, string>;
  namespace?: string;
}

export interface ContainerPort {
  containerPort: number;
  protocol?: string;
}

export interface Container {
  name: string;
  image: string;
  ports?: ContainerPort[];
  env?: Array<{ name: string; value: string }>;
}

export interface DeploymentSpec {
  replicas: number;
  selector: { matchLabels: Record<string, string> };
  template: {
    metadata: { labels: Record<string, string> };
    spec: { containers: Container[] };
  };
}

export interface Deployment {
  apiVersion: string;
  kind: 'Deployment';
  metadata: KubernetesMetadata;
  spec: DeploymentSpec;
}

Reading Typed YAML in Node.js

import { readFileSync } from 'fs';
import { parse } from 'yaml';
import { z } from 'zod';

// Define schema for validation
const ConfigSchema = z.object({
  database: z.object({
    host: z.string(),
    port: z.number().int(),
    name: z.string(),
  }),
  server: z.object({
    port: z.number().int(),
    cors: z.boolean().optional(),
  }),
});

type Config = z.infer<typeof ConfigSchema>;

function loadConfig(path: string): Config {
  const raw = readFileSync(path, 'utf-8');
  const parsed: unknown = parse(raw);
  return ConfigSchema.parse(parsed); // throws if invalid
}

GitHub Actions Workflow Typing

When building tools that process GitHub Actions workflows, type the YAML structure:

export interface WorkflowJob {
  name?: string;
  'runs-on': string | string[];
  needs?: string | string[];
  steps: Array<{
    name?: string;
    uses?: string;
    run?: string;
    with?: Record<string, string | number | boolean>;
    env?: Record<string, string>;
  }>;
}

export interface Workflow {
  name?: string;
  on: string | string[] | Record<string, unknown>;
  jobs: Record<string, WorkflowJob>;
}

For a live YAML-to-TypeScript converter, visit js2ts.com/yaml-to-typescript.

Share