Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zero Runtime Factory #3793

Open
miyaji255 opened this issue Jan 1, 2025 · 0 comments
Open

Zero Runtime Factory #3793

miyaji255 opened this issue Jan 1, 2025 · 0 comments
Labels
enhancement New feature or request.

Comments

@miyaji255
Copy link

miyaji255 commented Jan 1, 2025

What is the feature you are proposing?

Description

Since it is common for projects to use a single Env type, I propose using declaration merging as an alternative approach.

I believe this change can simplify type management and improve the developer experience, and this approach can also support presets.

Proposed Method

To address this, I propose modifying the Hono class as follows:

- class Hono<E extends Env = Env, ...>
+ class Hono<E extends Env = DefaultEnv, ...>

+ interface DefaultEnv { }
+ interface EnvBindings { }
+ interface EnvVariables { }

This allows developers to define and extend DefaultEnv for their projects without needing to specify Env types in every instance:

declare module "hono" {
  interface DefaultEnv {
    Bindings: EnvBindings;
    Variables: EnvVariables;
  }
  interface EnvBindings {
    lambdaContext: LambdaContext;
  }
  interface EnvVariables {
    foo: string;
  }
}

const app = new Hono();
const middleware: MiddlewareHandler = (c, next) => ...

Example for AWS Lambda

For example, adapters could automatically set Bindings when using AWS Lambda:

// aws-lambda/handler.ts
declare module "hono" {
  interface DefaultEnv {
    Bindings: EnvBindings
  }
  interface EnvBindings {
    event: LambdaEvent
    lambdaContext: LambdaContext
  }
}
export const handler ...
@miyaji255 miyaji255 added the enhancement New feature or request. label Jan 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request.
Projects
None yet
Development

No branches or pull requests

1 participant