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
-
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
env
function 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:
env
in 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.env
directly, or use some other abstraction, like t3-env ?key
was dynamic. You couldn't just pass astring
to 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