-
-
Notifications
You must be signed in to change notification settings - Fork 584
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
fix(types): Calculate Context<Env> type for each handler #3675
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3675 +/- ##
=======================================
Coverage 91.70% 91.70%
=======================================
Files 159 159
Lines 10145 10145
Branches 2862 2942 +80
=======================================
Hits 9303 9303
Misses 840 840
Partials 2 2 ☔ View full report in Codecov by Sentry. |
I used the following code to investigate how much type calculation costs vary. import { Hono } from '../../../src'
import { createMiddleware } from '../../../src/helper/factory'
const mw1 = createMiddleware<{ Variables: { foo: string } }>(async (c, next) => {
c.set('foo', 'bar')
await next()
})
const mw2 = createMiddleware<{ Variables: { bar: string } }>(async (c, next) => {
c.set('bar', 'baz')
await next()
})
const mw3 = createMiddleware<{ Variables: { baz: string } }>(async (c, next) => {
c.set('baz', 'qux')
await next()
})
const mw4 = createMiddleware<{ Variables: { qux: string } }>(async (c, next) => {
c.set('qux', 'quux')
await next()
})
const mw5 = createMiddleware<{ Variables: { quux: string } }>(async (c, next) => {
c.set('quux', 'corge')
await next()
})
const mw6 = createMiddleware<{ Variables: { corge: string } }>(async (c, next) => {
c.set('corge', 'grault')
await next()
})
const mw7 = createMiddleware<{ Variables: { grault: string } }>(async (c, next) => {
c.set('grault', 'garply')
await next()
})
const mw8 = createMiddleware<{ Variables: { garply: string } }>(async (c, next) => {
c.set('garply', 'waldo')
await next()
})
export const app = new Hono().get(
'/route1',
mw1,
mw2,
mw3,
mw4,
mw5,
mw6,
mw7,
mw8,
// Context<Env> at this 'c' is combined from all middlewares
async (c, next) => {
await next()
},
(c) => {
const foo = c.get('foo')
return c.json({ foo })
}
) |
The result is as follows.
|
@sushichan044 Thank you for handling it. Exactly. I also thought the decrease in performance would possibly be a pain point.
@m-shaka What do you think of it? |
8f4ca23
to
1af264b
Compare
closes #3587
This PR makes all
Context<Env>
in handlers respect type changes made by previous handlers.The author should do the following, if applicable
bun run format:fix && bun run lint:fix
to format the code