Skip to content

Commit

Permalink
add docs for emptyStringAsUndefined
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusmarminge committed Jan 24, 2024
1 parent f70c53a commit c803a47
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/src/app/docs/customization/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ export const env = createEnv({
});
```

## Treat empty strings as undefined

By default, T3 Env will feed the environment variables directly to the Zod validator. This means that if you have an empty string for a value that is supposed to be a number (e.g. `PORT=` in a ".env" file), Zod will flag
it as a type mismatch violation. Additionally, if you have an empty string for a value that is supposed to be a string with a default value (e.g. `DOMAIN=`in an ".env" file), the default value will never be applied. In order to solve these issues, you can set the`emptyStringAsUndefined`option to`true`.

```ts title="src/env.ts"
import { createEnv } from "@t3-oss/env-core";

export const env = createEnv({
// ...
// Treat empty strings as undefined.
emptyStringAsUndefined: false,
});
```

## Extending presets

Your env object may extend other presets by using the `extends` property. This can be used to include system environment variables for your deployment provider, or if you have a monorepo with multiple packages that share some environment variables.
Expand Down

1 comment on commit c803a47

@vercel
Copy link

@vercel vercel bot commented on c803a47 Jan 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

t3-env – ./docs

t3-env-git-main-t3-oss.vercel.app
env.t3.wtf
t3-env.vercel.app
env.t3.gg
t3-env-t3-oss.vercel.app

Please sign in to comment.