Your env handling is wrong in TypeScript

preview_player
Показать описание
Smash that 👍 and 🔔
Share to spread the love 🤗

Free Crash Course on Zod if you are interested:

👇 Subscribe for MOORE 👇

🌹 Support High Effort - Well Researched - Quality Content 🌹

~
Рекомендации по теме
Комментарии
Автор

curious what's the state of the art right now with dead code elimination? I remember that some frontend bundlers were just replacing `process.env.FOO` with the exact value of `FOO` at the build time making it later easy by the minifier to remove dead code.
But not so sure if that's still the case, maybe bundlers are smarter than before.

pawelula
Автор

Normally what I do and what I've seen is people exporting an object manually parsing the env vars they want and adding fallbacks etc. That adds types to every prop.

Like

```
export const config = {
timeout: +process.env.TIMEOUT || 0
}
```

config.timeout // will be a number

brunolm
Автор

but why using env.ts instead of .env what is difference .

ThanHtutZaw