How to set envs as number in t3stack
I would like the envs to be parsed as numbers/booleans straight from env.mjs, how to approach that?
23 Replies
instead of z.string() do this https://zod.dev/?id=numbers
GitHub
TypeScript-first schema validation with static type inference
TypeScript-first schema validation with static type inference
for booleans https://zod.dev/?id=booleans
GitHub
TypeScript-first schema validation with static type inference
TypeScript-first schema validation with static type inference
This will probably not work, I doubt it will parse itself
thx, I was looking for that!
I'm doing something wrong? Where should I put it?
Those values are defined as numbers
try this
adding the
number
as possible type Does not work 😦
i guess that env variables can't be numbers
like really won't allow
env variables can never be numbers
they can only be strings
even if the string contains numbers
you can use a transform maybe
at best you can transform at runtime
I don't see a reason why we shouldnt be able to validate and transform them in the env.mjs file and then use them as booleans/numbers
try transforming
but validating can only ensure its a string cause thats what it is
Imo this is a good feature to potentially support it out of box with t3stack & add that to docs
@julius @cje thoughts?
what's the feature request?
env variables are always strings - if you want them as a number or boolean, use
.transform
:
JSON.stringify({ processEnv: process.env, env: env }, null, 4)
then outputs this:getting some nasty error about the stypes not overlapping though... jsdoc is weird
they are correctly inferred though
Would be great to have it typed correctly without any errors out of box imo,
This example also could be potentially added into the docs imo
can you do
as unknown as SomeType
in jsdoc?
or maybe the underlying type is wrongCould you point where should I do it?
On this typeerrror