Closed AhmedBaset closed 7 months ago
i dont think this is possible, as the error suggests it creates a circular reference.
what's the use case why you wanna do this? I believe augmenting process.env here is kinda scary since we have no assurance if the type iss correct then considering transforms, default values etc aren't taken into account then.
e.g.:
export const env = createEnv({
server: {
DATABASE_URL: z.string().url().default("mysql://localhost:3306/db"),
},
runtimeEnv: {
DATABASE_URL: process.env.DATABASE_URL,
},
});
here env.DATABASE_URL
will be guaranteed to be a string, but process.env.DATABASE_URL
can be undefined. augmenting the type would potentailly cause a runtime error
Is there a way to augment
NodeJS.ProccessEnv
by extending theenv
object without rewriting them one by one.I've tried:
I get errors in:
Env
:Type alias 'Env' circularly references itself.ts(2456)
env
:'env' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.ts(7022)
;