Generators
Choose the right output generator for your workflow, from TypeScript and Zod to t3-env and declaration files.
Generator selection by outcome
| Goal | Generator |
|---|---|
| Typed compile-time hints in code | ts / typescript |
| Runtime schema validation with Zod | zod |
Drop-in env config for @t3-oss/env-nextjs | t3 |
Global process.env augmentation | declaration |
Available generators and outputs
ts — TypeScript types
Produces a type Env declaration and ProcessEnv namespace augmentation:
// env.generated.typescript.ts
export type Env = {
DATABASE_URL: string;
PORT: number;
DEBUG: boolean;
};
declare global {
namespace NodeJS {
interface ProcessEnv extends Env {}
}
}
zod — Zod schema
Produces a Zod v4 schema split into server and client objects:
// env.generated.zod.ts
import { z } from "zod";
export const serverSchema = z.object({
DATABASE_URL: z.string(),
PORT: z.coerce.number(),
});
export const clientSchema = z.object({
NEXT_PUBLIC_APP_URL: z.string().url(),
});
Variables prefixed with NEXT_PUBLIC_ are placed in clientSchema; all others go in serverSchema.
t3 — @t3-oss/env-nextjs
Produces a createEnv(...) call ready to drop into your project:
// env.generated.t3.ts
import { createEnv } from "@t3-oss/env-nextjs";
import { z } from "zod";
export const env = createEnv({
server: {
DATABASE_URL: z.string(),
},
client: {
NEXT_PUBLIC_APP_URL: z.string().url(),
},
runtimeEnv: process.env,
});
declaration — Ambient .d.ts
Augments NodeJS.ProcessEnv with types for all declared variables:
// env.generated.d.ts
declare global {
namespace NodeJS {
interface ProcessEnv {
DATABASE_URL: string;
PORT: string;
}
}
}
Combining generators
Pass multiple --format flags to produce all outputs in one run:
env-typegen -i .env.example -o env.generated.ts -f ts -f zod -f t3 -f declaration
Recommended combos
- App runtime safety:
-f zod -f declaration - Full-stack TypeScript teams:
-f ts -f zod -f declaration - Next.js +
@t3-oss/env-nextjs:-f t3 -f zod - Migration path from ad-hoc env typing: start with
-f ts, then addzod
FAQ
Is declaration enough without ts?
It augments process.env globally, but ts gives an explicit generated type that is often easier to import and test.
Can I skip t3 if I do not use Next.js?
Yes. t3 is optional and only needed if you want @t3-oss/env-nextjs output.