Skip to content

fix: allow env generic with interfaces#28694

Merged
FGoessler merged 2 commits intoprisma:mainfrom
SaubhagyaAnubhav:fix/env-interface-typing
Dec 3, 2025
Merged

fix: allow env generic with interfaces#28694
FGoessler merged 2 commits intoprisma:mainfrom
SaubhagyaAnubhav:fix/env-interface-typing

Conversation

@SaubhagyaAnubhav
Copy link
Copy Markdown
Contributor

Fixes #28617

Problem

The env helper rejected interface-based environment variable types because the previous generic constraint
Env extends Record<string, string | undefined> required an index signature that interfaces don’t have.
This caused TS2344 when following the documented example.

Fix

The type definition of env was updated and a new EnvKey helper type was introduced to filter valid keys.
This allows both interfaces and type aliases to work as expected without changing runtime behavior.

Changes Made

  • Updated env signature using a simplified generic pattern
  • Added EnvKey to restrict keys to string | undefined values
  • Added a type-level test ensuring interface + type alias compatibility
  • Kept all runtime logic untouched

Result

  • Interface support now matches documentation
  • Type aliases continue to work
  • Compile-time validation preserved
  • Backwards-compatible with no runtime impact

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Nov 24, 2025

CLA assistant check
All committers have signed the CLA.

@SaubhagyaAnubhav
Copy link
Copy Markdown
Contributor Author

@FGoessler pls review this PR

Copy link
Copy Markdown
Contributor

@FGoessler FGoessler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this tweak @SaubhagyaAnubhav 🎉

@FGoessler FGoessler merged commit d81b4b6 into prisma:main Dec 3, 2025
251 of 254 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

env() helper should allow interface generic

3 participants