-
Notifications
You must be signed in to change notification settings - Fork 2.1k
env() helper should allow interface generic #28617
Copy link
Copy link
Closed
Labels
kind/bugA reported bug.A reported bug.
Description
Bug description
This works (copied from an example in the docs)
import 'dotenv/config'
import { defineConfig, env } from "prisma/config";
type Env = {
DATABASE_URL: string
}
export default defineConfig({
schema: 'prisma/schema.prisma',
migrations: {
path: 'prisma/migrations',
},
datasource: {
url: env<Env>('DATABASE_URL'),
},
});This, however, does not work
Notice how I changed from type to interface for Env
import 'dotenv/config'
import { defineConfig, env } from "prisma/config";
interface Env {
DATABASE_URL: string
}
export default defineConfig({
schema: 'prisma/schema.prisma',
migrations: {
path: 'prisma/migrations',
},
datasource: {
url: env<Env>('DATABASE_URL'),
},
});The code above gives the following error
Type 'Env' does not satisfy the constraint 'Record<string, string | undefined>'.
Index signature for type 'string' is missing in type 'Env'. (ts 2344)
I think the generic for env should be updated to also allow using an interface like the one in the example above
Severity
🔹 Minor: Unexpected behavior, but does not block development
Reproduction
- Follow your own docs here: https://www.prisma.io/docs/orm/reference/prisma-config-reference#type-safe-environment-variables
- Change
Envfrom being atypeto being aninterfaceinstead.
Expected vs. Actual Behavior
Expected:
No TS errors
Actual:
Type 'Env' does not satisfy the constraint 'Record<string, string | undefined>'.
Index signature for type 'string' is missing in type 'Env'. (ts 2344)
Frequency
Consistently reproducible
Does this occur in development or production?
Only in development (e.g., CLI tools, migrations, Prisma Studio)
Is this a regression?
No, this is new functionality
Workaround
Add an index signature to the interface, like this:
interface Env {
[key: string]: string | undefined
DATABASE_URL: undefined
}Prisma Schema & Queries
N/A
Prisma Config
import { defineConfig, env } from 'prisma/config'
interface Env {
DATABASE_URL: undefined
}
const url = env<Env>('DATABASE_URL')
export default defineConfig({
schema: 'db/schema.prisma',
migrations: {
path: 'db/migrations',
},
datasource: {
url,
},
})Logs & Debug Info
N/A
Environment & Setup
- OS: macOS
- Database: Prisma Postgres
- Node.js version: v24.11.1
Prisma Version
❯ npx prisma -v
prisma : 6.19.0
@prisma/client : 6.19.0
Computed binaryTarget : darwin-arm64
Operating System : darwin
Architecture : arm64
Node.js : v24.11.1
TypeScript : 5.9.2
Query Engine (Node-API) : libquery-engine 2ba551f319ab1df4bc874a89965d8b3641056773 (at node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
PSL : @prisma/prisma-schema-wasm 6.19.0-26.2ba551f319ab1df4bc874a89965d8b3641056773
Schema Engine : schema-engine-cli 2ba551f319ab1df4bc874a89965d8b3641056773 (at node_modules/@prisma/engines/schema-engine-darwin-arm64)
Default Engines Hash : 2ba551f319ab1df4bc874a89965d8b3641056773
Studio : 0.511.0
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
kind/bugA reported bug.A reported bug.