boolean()
Create a boolean validator that parses true/false string values.
boolean()
Creates a validator that accepts boolean values. Supports string and numeric coercion.
Signature
function boolean(): BooleanValidator
Accepted Values
| Input | Result | Notes |
|---|---|---|
true | ✅ true | Actual boolean |
false | ✅ false | Actual boolean |
"true" | ✅ true | Case-insensitive, trimmed |
"false" | ✅ false | Case-insensitive, trimmed |
"TRUE" | ✅ true | Case-insensitive |
"1" | ✅ true | String "1" |
"0" | ✅ false | String "0" |
"yes" | ✅ true | Case-insensitive |
"no" | ✅ false | Case-insensitive |
"on" | ✅ true | Case-insensitive |
"off" | ✅ false | Case-insensitive |
"y" | ✅ true | Shorthand "yes" |
"n" | ✅ false | Shorthand "no" |
"t" | ✅ true | Shorthand "true" |
"f" | ✅ false | Shorthand "false" |
1 | ✅ true | Number 1 |
0 | ✅ false | Number 0 |
2 | ❌ Type error | Only 1 and 0 are accepted |
null | ❌ Type error |
Refinements
boolean() has no type-specific refinements. It only has the
chainable methods (.optional(), .default(), .describe(),
.secret(), .validate()).
Examples
Basic boolean
const env = defineEnv({
DEBUG: boolean(),
})
// With process.env.DEBUG = "true"
// env.DEBUG → true
Optional boolean
const env = defineEnv({
FEATURE_X_ENABLED: boolean().optional(),
})
// env.FEATURE_X_ENABLED: boolean | undefined
Boolean with default
const env = defineEnv({
ENABLE_LOGGING: boolean().default(true),
})
// env.ENABLE_LOGGING: boolean (defaults to true if not set)
Common patterns
const env = defineEnv({
// Feature flags
ENABLE_NEW_DASHBOARD: boolean().default(false),
SHOW_EXPERIMENTAL: boolean().optional(),
// Logging controls
DEBUG: boolean().default(false).describe("Enable debug logging"),
VERBOSE: boolean().default(false),
})How is this guide?
Last updated on Jun 30, 2026