More type safety for env function key parameter
#148
ZilvinasAbr
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Thank you for introducing such nice library to solve a key issue of Next.js!
Wanted to share some random idea that could maybe be used for this library.
Currently the implementation of
envfunction checks if provided environment variable key parameter is withNEXT_PUBLIC_prefix on runtime (if client-side):What if instead we achieved this safety statically with Typescript? Example:
After this change, Typescript would yell if trying to pass a string without such prefix.
Issues with this approach:
envin server-side without theNEXT_PUBLIC_prefix, as this is currently allowed and just returns the env variable fromprocess.env. But maybe this would be okay since for server-side env variables the user can just take it fromprocess.envdirectly, or use some other abstraction, like t3-env ?keywas dynamic. You couldn't just pass astringto it. You would need to do some shenanigans in order to pass it, e.g.env(value as NEXT_PUBLIC_${string}).Beta Was this translation helpful? Give feedback.
All reactions