env-typegen-typescript-types-from-env

Verified·Scanned 2/18/2026

Generates TypeScript types from a .env file and provides CLI installation/usage. It instructs running npm install -g @lxgicstudios/env-typegen / npx @lxgicstudios/env-typegen and reads environment variables like API_KEY and .env.

from clawhub.ai·v1a0f9f8·2.3 KB·0 installs
Scanned from 0.1.0 at 1a0f9f8 · Transparency log ↗
$ vett add clawhub.ai/lxgicstudios/env-typegen-typescript-types-from-env

Env Typegen

Generate TypeScript types from your .env file. Smart type inference for numbers, booleans, URLs.

Installation

npm install -g @lxgicstudios/env-typegen

Commands

Generate Types

npx @lxgicstudios/env-typegen
npx @lxgicstudios/env-typegen .env.local
npx @lxgicstudios/env-typegen -o src/types/env.d.ts

With Zod Schema

npx @lxgicstudios/env-typegen --zod

Example

Input .env:

# Database
DATABASE_URL=postgresql://localhost:5432/db
DB_POOL_SIZE=10

# Server
PORT=3000
DEBUG=true

# API
API_KEY=sk_live_abc123

Output:

export interface Env {
  /** Database */
  DATABASE_URL: string;
  DB_POOL_SIZE: number;
  /** Server */
  PORT: number;
  DEBUG: boolean;
  /** API */
  API_KEY: string;
}

export function getEnv(): Env {
  return {
    DATABASE_URL: process.env.DATABASE_URL || '',
    DB_POOL_SIZE: Number(process.env.DB_POOL_SIZE),
    PORT: Number(process.env.PORT),
    DEBUG: ['true', '1', 'yes'].includes(process.env.DEBUG?.toLowerCase() || ''),
    API_KEY: process.env.API_KEY || '',
  };
}

declare global {
  namespace NodeJS {
    interface ProcessEnv {
      DATABASE_URL: string;
      DB_POOL_SIZE: string;
      PORT: string;
      DEBUG: string;
      API_KEY: string;
    }
  }
}

Type Inference

PatternType
PORT=3000number
DEBUG=trueboolean
API_URL=https://...string (URL)
EMAIL=a@b.comstring (email)
Everything elsestring

Options

OptionDescription
-i, --inputInput file (default: .env)
-o, --outputOutput file (default: env.d.ts)
--zodGenerate Zod schema too
--nameInterface name (default: Env)

Common Use Cases

Generate for project:

npx @lxgicstudios/env-typegen -o src/types/env.d.ts

With runtime validation:

npx @lxgicstudios/env-typegen --zod -o src/env.ts

Built by LXGIC Studios

🔗 GitHub · Twitter