DEV Community

Cover image for Typing env variables on typescript
Wilian Martinez
Wilian Martinez

Posted on

Typing env variables on typescript

As a backend developer, I've been working with typescript, on some projects we are required to use different types of environment files, the most common is using environment files, but there are some specific cases where we need to use other types because the tools that we use requires a yaml, JSON or other file formats, we already have a perfect tool like dotenv-yaml - npm or dotenv - npm. But something comes to my mind, what if we have a package that can support any env files 🤔...

So I made a try, and I created ts-env, we can manage different types of env files, currently supporting YAML, 'TOML', 'JSON' files

default_config

Typing

It also supports typing the process.env which helps a lot to know which variables we have on the env file.

type_config

So we can have a lint suggestion on the editor

suggest_lint

Conclusion

I don't know if this is a real problem, if it is not, at least was interesting doing int, so let me know what do you think

Top comments (0)