I'm using TypeScript. How does 'dotenv' work with TypeScript?

Responsive Ad Header

Question

Grade: Education Subject: Support
I'm using TypeScript. How does 'dotenv' work with TypeScript?
Asked by:
61 Viewed 61 Answers

Answer (61)

Best Answer
(300)
To use `dotenv` with TypeScript, you need to tell TypeScript that the `process` object has environment variables. You can do this by adding the following declaration to a `d.ts` file (e.g., `env.d.ts`) in your project: `declare global { interface ProcessEnv { [key: string]: string | undefined; } }`.