diff --git a/src/types.test.ts b/src/types.test.ts index 0e2aff6e6..e05720dcc 100644 --- a/src/types.test.ts +++ b/src/types.test.ts @@ -401,6 +401,53 @@ describe('OnHandlerInterface', () => { } type verify = Expect> }) + + test('app.on(method, path, ...10 handlers) - last handler response type should be inferred', () => { + const noop: MiddlewareHandler = async (_c, next) => { + await next() + } + const route = app.on('GET', '/x10', noop, noop, noop, noop, noop, noop, noop, noop, noop, (c) => + c.json({ success: true }) + ) + type Actual = ExtractSchema['/x10']['$get']['output'] + type Expected = { success: true } + type verify = Expect> + }) + + test('app.on(method[], path, ...9 handlers) - last handler response type should be inferred', () => { + const noop: MiddlewareHandler = async (_c, next) => { + await next() + } + const route = app.on(['GET'], '/x9-arr', noop, noop, noop, noop, noop, noop, noop, noop, (c) => + c.json({ success: true }) + ) + type Actual = ExtractSchema['/x9-arr']['$get']['output'] + type Expected = { success: true } + type verify = Expect> + }) + + test('app.on(method[], path, ...10 handlers) - last handler response type should be inferred', () => { + const noop: MiddlewareHandler = async (_c, next) => { + await next() + } + const route = app.on( + ['GET'], + '/x10-arr', + noop, + noop, + noop, + noop, + noop, + noop, + noop, + noop, + noop, + (c) => c.json({ success: true }) + ) + type Actual = ExtractSchema['/x10-arr']['$get']['output'] + type Expected = { success: true } + type verify = Expect> + }) }) describe('TypedResponse', () => { diff --git a/src/types.ts b/src/types.ts index ab9f47987..6d754dc3d 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1790,7 +1790,7 @@ export interface OnHandlerInterface< ] ): HonoBase< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10, E11]>, - S & ToSchema, I10, MergeTypedResponse>>, + S & ToSchema, I10, MergeTypedResponse>, BasePath, MergePath > @@ -2095,7 +2095,7 @@ export interface OnHandlerInterface< ] ): HonoBase< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10]>, - S & ToSchema, I9, MergeTypedResponse>>, + S & ToSchema, I9, MergeTypedResponse>, BasePath, MergePath > @@ -2143,7 +2143,7 @@ export interface OnHandlerInterface< ] ): HonoBase< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10, E11]>, - S & ToSchema, I10, MergeTypedResponse>>, + S & ToSchema, I10, MergeTypedResponse>, BasePath, MergePath >