-
-
Notifications
You must be signed in to change notification settings - Fork 996
Closed
Labels
Description
What version of Hono are you using?
4.10.0
What runtime/platform is your app running on? (with version if possible)
What steps can reproduce the bug?
import { Hono } from 'hono'
import { createMiddleware } from 'hono/factory'
const sampleMiddleware = createMiddleware(async (c) => {
console.warn(c.req.url.length)
})
const _app = new Hono()
.use(sampleMiddleware) // Error hereWhat is the expected behavior?
Works normally
What do you see instead?
Additional information
This is because the response type of the middleware handler that is created got created as HandlerResponse<any> instead of the default = Response, not sure why this happens, as the declaration looks good to me honestly, and it works fine for non-async middleware handler and async handler that returns any response.
From my test it can be fixed easily by changing from
export type MiddlewareHandler<E extends Env = any, P extends string = string, I extends Input = {}, R extends HandlerResponse<any> = Response>
to
export type MiddlewareHandler<E extends Env = any, P extends string = string, I extends Input = {}, R extends HandlerResponse<any> = any>,
Similar to how Handler type is declared.
Reactions are currently unavailable