I had the impression that adding environment variables to environment.d.ts would ensure that they had the proper types.
I have @types/node as a dev-dependency, and have an environment.d.ts containing the following
declare global {
namespace NodeJS {
interface ProcessEnv {
DATABASE_URL: string;
}
}
}
export {};
However, when I attempt to use DATABASE_URL, e.g. in
import PgPromise from "pg-promise";
const db = PgPromise()(process.env.DATABASE_URL || "");
I'm still getting the error
error TS2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string | IConnectionParameters<IClient>'.
Type 'undefined' is not assignable to type 'string | IConnectionParameters<IClient>'.
Is there any way to ensure that DATABASE_URL is of type string, as opposed to string | undefined? Am I missing something?