You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What runtime/platform is your app running on? (with version if possible)
Deno (npm package)
What steps can reproduce the bug?
Following the Documentation, I'm adding a variable into the context via middleware. When I use a normal app.get or app.post function, there are no errors. However, when I use app.on for multiple routes in one function, Typescript errors stating the types c and c are incompatible.
I've attached a minimal reproducible example below.
import{Hono}from"hono";import{createMiddleware}from"hono/factory";constapp=newHono();// Extra vars for contextinterfaceCtxOptions{Variables: {testString: string;};}constmessageMiddleware=createMiddleware<CtxOptions>(async(c,next)=>{console.log("Middleware!");c.set("testString","hello!");awaitnext();});// No Errorsapp.get("/route",messageMiddleware,(c)=>{returnc.body("Hello!")})// Errors on messageMiddlewareapp.on("GET",["/route","/altRoute"],messageMiddleware,(c)=>{returnc.body("Hello!")})
What is the expected behavior?
The middleware validates with app.on in the same way as using app.get, app.post, etc.
What do you see instead?
Type error stating that the contexts are incompatible
Check file:///Users/kingbri/Documents/projects/deno-test/main.ts
error: TS2769 [ERROR]: No overload matches this call.
The last overload gave the following error.
Argument of type 'MiddlewareHandler<CtxOptions, string, {}>' is not assignable to parameter of type 'H<BlankEnv, any, {}, HandlerResponse<any>>'.
Type 'MiddlewareHandler<CtxOptions, string, {}>' is not assignable to type 'MiddlewareHandler<BlankEnv, any, {}>'.
Types of parameters 'c' and 'c' are incompatible.
Type 'Context<BlankEnv, any, {}>' is not assignable to type 'Context<CtxOptions, string, {}>'.
Types of property 'get' are incompatible.
Type 'Get<BlankEnv>' is not assignable to type 'Get<CtxOptions>'.
Property 'Variables' is missing in type 'BlankEnv' but required in type 'CtxOptions'.
messageMiddleware,
~~~~~~~~~~~~~~~~~
at file:///Users/kingbri/Documents/projects/deno-test/main.ts:30:5
'Variables' is declared here.
Variables: {
~~~~~~~~~
at file:///Users/kingbri/Documents/projects/deno-test/main.ts:8:5TS2771 [ERROR]: The last overload is declared here.
at file:///Users/kingbri/Library/Caches/deno/npm/registry.npmjs.org/hono/4.6.14/dist/types/types.d.ts:1211:5
Additional information
No response
The text was updated successfully, but these errors were encountered:
What version of Hono are you using?
4.6.14
What runtime/platform is your app running on? (with version if possible)
Deno (npm package)
What steps can reproduce the bug?
Following the Documentation, I'm adding a variable into the context via middleware. When I use a normal
app.get
orapp.post
function, there are no errors. However, when I useapp.on
for multiple routes in one function, Typescript errors stating the typesc
andc
are incompatible.I've attached a minimal reproducible example below.
What is the expected behavior?
The middleware validates with
app.on
in the same way as usingapp.get, app.post
, etc.What do you see instead?
Type error stating that the contexts are incompatible
Additional information
No response
The text was updated successfully, but these errors were encountered: