Typegen
Generate types
typegen
Generates TypeScript type definitions for your environment variables.
Usage
env-mage typegen [options]Options
| Option | Description | Default |
|---|---|---|
--file <path> | Source file | .env |
--output <path> | Output file | env.d.ts |
--format <format> | Output format (typescript, jsdoc, or both) | typescript |
--guess-types | Try to infer types | true |
--no-guess-types | Treat all variables as strings | false |
Example
env-mage typegen --output src/types/env.d.ts --format typescriptExample Output
✓ Reading environment file: .env
✓ Found 8 environment variables
✓ Inferring variable types
ℹ DATABASE_URL: string
ℹ PORT: number
ℹ DEBUG: boolean
ℹ API_KEY: string
✓ Generating TypeScript types
✓ Writing output to: src/types/env.d.ts
✓ Type definitions created successfully!Generated File Example
declare namespace NodeJS {
interface ProcessEnv {
DATABASE_URL: string;
PORT: number;
DEBUG: boolean;
API_KEY: string;
}
}Things to Know
- Automatically infers types (string, number, boolean) from values
- Use
--no-guess-typesfor all string types - Works with TypeScript projects to provide type safety
- Import the generated file once in your project for global types