Skip to content

Unable to extend env when ProcessEnv has been manipulated #1132

@ehyland

Description

@ehyland

When a non optional property has been defined on ProcessEnv by interface merging, it is not possible to use execa's env & extendEnv options to add additional environment variables to execa process.

Typescript playground example

Example

import { config } from "~/config.server";
import { execa } from "execa";

// from @remix-run/node
interface ProcessEnv {
  NODE_ENV: "development" | "production" | "test";
}

// attempting to extend process env results in TS error "No overload matches this call."
const $ = execa({
  stdio: "inherit",
  extendEnv: true,
  env: {
    DATABASE_URL: config.DATABASE_URL,
  },
});

await $`prisma db push --accept-data-loss`;

Suggestion

Instead of env option being typed as typeof import('node:process').env. Maybe it should be typed as Record<string, string | undefined>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions