Skip to content

Do TypeBox support String Boolean type or Boolean Type Coercion? #1067

Answered by sinclairzx81
deanrih asked this question in Q&A
Discussion options

You must be logged in to vote

@deanrih Hi,

The Value.Convert() function will coerce a string "true" into a boolean true. TypeBox treats this as an explicit call you need to make rather than via configuration on the type. The following loosely achieves this.

const Environment = Type.Object({
  DEBUG: Type.Boolean()
})

const R = Value.Convert(Environment, process.env) // will convert "true" to true if possible.

However it's recommended you use Value.Parse for environment loading. TypeBox exposes quite a few low level Value operations for flexibility, but the Parse function internally implements all these operations in a standard way to process a value how you would expect.

const Environment = Type.Object({
  DEBUG: Type.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@deanrih
Comment options

Answer selected by deanrih
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants