diff --git a/src/types.test.ts b/src/types.test.ts index 9a4720029..d1ec00107 100644 --- a/src/types.test.ts +++ b/src/types.test.ts @@ -277,6 +277,14 @@ describe('OnHandlerInterface', () => { } type verify = Expect> }) + + test('app.on(method, path[], middleware, handler) should not throw a type error', () => { + const middleware: MiddlewareHandler<{ Variables: { foo: string } }> = async () => {} + app.on('GET', ['/a', '/b'], middleware, (c) => { + expectTypeOf(c.var.foo).toEqualTypeOf() + return c.json({}) + }) + }) }) describe('TypedResponse', () => { diff --git a/src/types.ts b/src/types.ts index f58f162bd..bfa96a260 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1745,10 +1745,10 @@ export interface OnHandlerInterface< ): HonoBase, I, MergeTypedResponse>, BasePath> // app.on(method | method[], path[], ...handlers[]) - = any>( + = any, E2 extends Env = E>( methods: string | string[], paths: string[], - ...handlers: H[] + ...handlers: H[] ): HonoBase>, BasePath> }