Skip to content

Commit

Permalink
fix(types): correct app.on(method,path[],middleware,handler) type (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
yusukebe authored Jan 5, 2025
1 parent 5af7b4f commit 100745a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,14 @@ describe('OnHandlerInterface', () => {
}
type verify = Expect<Equal<Expected, Actual>>
})

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<string>()
return c.json({})
})
})
})

describe('TypedResponse', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1745,10 +1745,10 @@ export interface OnHandlerInterface<
): HonoBase<E, S & ToSchema<string, MergePath<BasePath, P>, I, MergeTypedResponse<R>>, BasePath>

// app.on(method | method[], path[], ...handlers[])
<I extends Input = BlankInput, R extends HandlerResponse<any> = any>(
<I extends Input = BlankInput, R extends HandlerResponse<any> = any, E2 extends Env = E>(
methods: string | string[],
paths: string[],
...handlers: H<E, any, I, R>[]
...handlers: H<E2, any, I, R>[]
): HonoBase<E, S & ToSchema<string, string, I, MergeTypedResponse<R>>, BasePath>
}

Expand Down

0 comments on commit 100745a

Please sign in to comment.