Skip to content
Discussion options

You must be logged in to vote

The Trade-offs of "Env Accumulation" in Hono

This is a fascinating architectural question! You've correctly identified that Hono's createFactory<Env> pattern is "explicit-first," and you're wondering if we can pivot to an "inference-first" model.

The Technical Limitation (The "Circular Type" Problem):
In TypeScript, once you instantiate const app = new Hono(), its generic Env is "locked" to either what you provided or the default BlankEnv. While .use() can extend the internal state of the application, it cannot "reach back" and mutate the type of the app instance itself without creating a deep chain of ReturnType nesting.

If we tried to infer Env from the .use() chain, every call to .use()

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@Andrew1326
Comment options

@lubiah
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by lubiah
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants