vercel / next.js

The React Framework
https://nextjs.org
MIT License
122.59k stars 26.23k forks source link

feat: type check for `env` #67157

Open devjiwonchoi opened 4 days ago

devjiwonchoi commented 4 days ago

Port of #48029

Why?

Users can benefit the autocomplete and type-safe environment variable experience.

What?

This PR added experimental.typedEnv that generates a .d.ts file on Dev Server. It generates from the loaded env files, except production specific files like .env.production.local.

How?

When starting the dev server, we read off the env files and next config.

If we validate that there is experimental.typedEnv set as true in next config, we generate a env.d.ts file inside the distDir (.next by default).

If there is a change in the env files, we rewrite the env.d.ts file.

Fixes NEXT-542

ijjk commented 4 days ago

Tests Passed