Skip to content

Provide an interface that lists the known environment names #23075

Description

@sapphi-red

Description

It would be nice if we can provide input suggestions for

  • the config:
    export default defineConfig({
      environments: {
        s
        ^^^ input suggestion here
      }
    })
  • codes in meta-frameworks:
    server.environments.s
                        ^^^ input suggestion here

Suggested solution

Add the KnownEnvironment type that lists the known environment names

// this `Record<string & {}, never>` is to force the value of extended keys to be `never`
interface KnownEnvironment extends Record<string & {}, never> {
  client: never
  ssr: never
}
type KnownEnvironmentNames = keyof KnownEnvironment

type Environments = Partial<Record<KnownEnvironmentNames, string>>

Plugins / Meta-frameworks can extend by:

declare module 'vite' {
  interface KnownEnvironment {
    myEnv: never
  }
}

Alternative

No response

Additional context

This is also useful for vitejs/ecosystem#10

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    p2-nice-to-haveNot breaking anything but nice to have (priority)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions