I have the following types:
declare global {
namespace NodeJS {
interface ProcessEnv {
MONGO_DB: string;
JWT_SECRET: string;
NODE_ENV: 'dev' | 'staging' | 'production';
}
}
}
export {};
So it would not be possible to get process.env.something because something doesn't exists in the type definition, unless of course you ignore the type error that will come out.
The thing is, even if I try to process.env.JWT_SECRET, and run typescript check, ts will still throw an error like string | undefined is not assignable to type string because somehow process.env.JWT_SECRET is still being treated as string | undefined, even though I have explicit check (the for loop above) that ensures it will never have undefined values, I even used Required which I thought would ensure that Partial is undone.