CtroEnv
ctroenvType-Safe Environment Variables
Getting StartedQuick StartCore Concepts
defineEnv()string()number()boolean()pick()Chainable MethodsRefinementsError HandlingSchema Composition
CLI Overviewctroenv validatectroenv generatectroenv checkctroenv docsctroenv initCLI Configuration
Node AdapterVite AdapterNext.js Adapter
Migration from t3-envMigration from envalidMigration from dotenv

pick()

Create an enum validator that restricts values to a specific set of allowed options.

  1. Docs
  2. Core API

pick()

Creates a validator that accepts only specific string values (like an enum).

Signature

function pick<T extends readonly string[]>(values: T): PickValidator<T>

Parameters

ParamTypeDescription
valuesreadonly string[]Array of allowed string values

Accepted Values

Only exact string matches from the provided list:

const env = defineEnv({
  NODE_ENV: pick(["development", "staging", "production"]),
})
// ✅ "development"
// ✅ "staging"
// ✅ "production"
// ❌ "dev" (not in the list)
// ❌ "Development" (case-sensitive)
// ❌ 42 (wrong type)

Fuzzy Suggestions

When the input doesn't match any value, pick() compares case-insensitively and by prefix to suggest the closest match:

const env = defineEnv({
  LOG_LEVEL: pick(["debug", "info", "warn", "error"]),
})
// With LOG_LEVEL="inf"
// Error: Expected one of 'debug', 'info', 'warn', 'error', received "inf"
// Suggestion: Did you mean 'info'?

Type Inference

The TypeScript type is inferred as a union of the supplied literals:

const env = defineEnv({
  NODE_ENV: pick(["dev", "staging", "prod"]),
})
// env.NODE_ENV: "dev" | "staging" | "prod"

This enables exhaustive checking:

switch (env.NODE_ENV) {
  case "dev": break
  case "staging": break
  case "prod": break
  // TypeScript error if a case is missing
}

Examples

Environment mode

const env = defineEnv({
  NODE_ENV: pick(["development", "production"]).default("development"),
})
// env.NODE_ENV: "development" | "production"

Log level

const env = defineEnv({
  LOG_LEVEL: pick(["debug", "info", "warn", "error"]).default("info"),
})

Deployment region

const env = defineEnv({
  REGION: pick(["us-east-1", "us-west-2", "eu-west-1"]),
})

With optional

const env = defineEnv({
  CACHE_STRATEGY: pick(["memory", "redis", "memcached"]).optional(),
})
// env.CACHE_STRATEGY: "memory" | "redis" | "memcached" | undefined

How is this guide?

Edit on GitHub

Last updated on Jun 24, 2026

Previousboolean()NextChainable Methods

On this page

SignatureParametersAccepted ValuesFuzzy SuggestionsType InferenceExamplesEnvironment modeLog levelDeployment regionWith optional