Skip to content
brought to you byVoidZero

Environment Variables ​

Imported from "void/env".

defineEnv(schema) ​

Call defineEnv() in env.ts to register your schema and return the typed env object. Void validates production secrets before deployment and checks values when the Worker starts.

ts
import { defineEnv, string, number, oneOf, url } from 'void/env';

export default defineEnv({
  STRIPE_KEY: string(),
  PORT: number().default(3000),
  NODE_ENV: oneOf(['development', 'production']),
  VITE_PUBLIC_URL: url(),
});

env ​

Typed runtime proxy for declared env keys. Unknown keys and bindings pass through as unknown.

ts
import { env } from 'void/env';

const port = env.PORT;

Schema helpers ​

void/env includes Standard Schema-compatible helpers: string(), number(), boolean(), url(), email(), oneOf([...]), and json<T>(). Each helper supports .optional() and .default(value).

Non-client keys are server values and use remote secret storage in production. VITE_* keys are public build-time client values. Validation errors redact invalid values.

Types ​

void/env also provides global Cloudflare environment types:

ts
/// <reference types="void/env" />

Declares the Cloudflare.Env namespace with DB, KV, STORAGE, AI, SANDBOX, and ASSETS binding types.

For handler context variables such as c.set() and c.get(), augment CloudContextVariables. This is separate from Cloudflare.Env, which types worker bindings. Framework adapters such as @void/vue, @void/react, and @void/svelte also augment CloudContextVariables to add the shared key used by useShared().