Skip to content

Commit

Permalink
feat: add AdapterEnv interface for ambient extension
Browse files Browse the repository at this point in the history
The `AdapterRequestContext#env` method uses this interface to provide type safety at compile-time. It allows the user to make certain assumptions about the existence of particular environment variables.
  • Loading branch information
aleclarson committed Jan 2, 2025
1 parent 15aa5ae commit a4cc8ee
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/base/core/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* Interface defining the shape of environment variables
*/
export interface AdapterEnv {}

export type AdapterEnvKey = keyof AdapterEnv | (string & {});

/**
* Request context as dispatched by the platform adapter
*/
Expand All @@ -24,7 +31,9 @@ export interface AdapterRequestContext<P = unknown> {
*
* @returns The value of the variable or undefined if it doesn't exist.
*/
env(variable: string): string | undefined;
env<K extends AdapterEnvKey>(
variable: K,
): K extends keyof AdapterEnv ? AdapterEnv[K] : string | undefined;
/**
* Signal that the request hasn't been handled and the returned response is
* a placeholder (usually a 404). In this case the adapter should handle the
Expand Down

0 comments on commit a4cc8ee

Please sign in to comment.