We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Since it is common for projects to use a single Env type, I propose using declaration merging as an alternative approach.
Env
I believe this change can simplify type management and improve the developer experience, and this approach can also support presets.
presets
To address this, I propose modifying the Hono class as follows:
Hono
- 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:
DefaultEnv
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) => ...
For example, adapters could automatically set Bindings when using AWS Lambda:
Bindings
// aws-lambda/handler.ts declare module "hono" { interface DefaultEnv { Bindings: EnvBindings } interface EnvBindings { event: LambdaEvent lambdaContext: LambdaContext } } export const handler ...
The text was updated successfully, but these errors were encountered:
No branches or pull requests
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:This allows developers to define and extend
DefaultEnv
for their projects without needing to specifyEnv
types in every instance:Example for AWS Lambda
For example, adapters could automatically set
Bindings
when using AWS Lambda:The text was updated successfully, but these errors were encountered: