From 64a24d7b7788f60060d29f6c5d8f258cf81dfd30 Mon Sep 17 00:00:00 2001 From: Agata Naomichi Date: Tue, 23 Jan 2024 17:26:22 +0900 Subject: [PATCH] fix!(types): Fix context type when chaining routes with middlewares (#2046) * fix(types): Fix handler return types not to leak Context types * fix specs * denoify * fix specs * yarm format:fix && yarn denoify * Add tests --- deno_dist/types.ts | 56 +---- src/types.test.ts | 536 ++++++++++++++++++++++++++++++++------------- src/types.ts | 56 +---- 3 files changed, 404 insertions(+), 244 deletions(-) diff --git a/deno_dist/types.ts b/deno_dist/types.ts index 9d6d44e3b..6f9f6e0fe 100644 --- a/deno_dist/types.ts +++ b/deno_dist/types.ts @@ -394,11 +394,7 @@ export interface HandlerInterface< >( path: P, handler: H - ): Hono< - IntersectNonAnyTypes<[E, E2]>, - S & ToSchema, I['in'], MergeTypedResponseData>, - BasePath - > + ): Hono, I['in'], MergeTypedResponseData>, BasePath> // app.get(path, handler x2) < @@ -412,11 +408,7 @@ export interface HandlerInterface< >( path: P, ...handlers: [H, H] - ): Hono< - IntersectNonAnyTypes<[E, E2, E3]>, - S & ToSchema, I2['in'], MergeTypedResponseData>, - BasePath - > + ): Hono, I2['in'], MergeTypedResponseData>, BasePath> // app.get(path, handler x3) < @@ -432,11 +424,7 @@ export interface HandlerInterface< >( path: P, ...handlers: [H, H, H] - ): Hono< - IntersectNonAnyTypes<[E, E2, E3, E4]>, - S & ToSchema, I3['in'], MergeTypedResponseData>, - BasePath - > + ): Hono, I3['in'], MergeTypedResponseData>, BasePath> // app.get(path, handler x4) < @@ -459,11 +447,7 @@ export interface HandlerInterface< H, H ] - ): Hono< - IntersectNonAnyTypes<[E, E2, E3, E4, E5]>, - S & ToSchema, I4['in'], MergeTypedResponseData>, - BasePath - > + ): Hono, I4['in'], MergeTypedResponseData>, BasePath> // app.get(path, handler x5) < @@ -489,11 +473,7 @@ export interface HandlerInterface< H, H ] - ): Hono< - IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>, - S & ToSchema, I5['in'], MergeTypedResponseData>, - BasePath - > + ): Hono, I5['in'], MergeTypedResponseData>, BasePath> // app.get(path, handler x6) < @@ -522,11 +502,7 @@ export interface HandlerInterface< H, H ] - ): Hono< - IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>, - S & ToSchema, I6['in'], MergeTypedResponseData>, - BasePath - > + ): Hono, I6['in'], MergeTypedResponseData>, BasePath> // app.get(path, handler x7) < @@ -558,11 +534,7 @@ export interface HandlerInterface< H, H ] - ): Hono< - IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>, - S & ToSchema, I7['in'], MergeTypedResponseData>, - BasePath - > + ): Hono, I7['in'], MergeTypedResponseData>, BasePath> // app.get(path, handler x8) < @@ -597,11 +569,7 @@ export interface HandlerInterface< H, H ] - ): Hono< - IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>, - S & ToSchema, I8['in'], MergeTypedResponseData>, - BasePath - > + ): Hono, I8['in'], MergeTypedResponseData>, BasePath> // app.get(path, handler x9) < @@ -639,11 +607,7 @@ export interface HandlerInterface< H, H ] - ): Hono< - IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10]>, - S & ToSchema, I9['in'], MergeTypedResponseData>, - BasePath - > + ): Hono, I9['in'], MergeTypedResponseData>, BasePath> // app.get(path, handler x10) < @@ -685,7 +649,7 @@ export interface HandlerInterface< H ] ): Hono< - IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10, E11]>, + E, S & ToSchema, I10['in'], MergeTypedResponseData>, BasePath > diff --git a/src/types.test.ts b/src/types.test.ts index b3b4fe08f..2f64e8544 100644 --- a/src/types.test.ts +++ b/src/types.test.ts @@ -836,158 +836,6 @@ describe('c.var with chaining - test only types', () => { return c.json(0) }) - // app.get('/', handler...) - - new Hono().get('/', mw1).get('/', (c) => { - expectTypeOf(c.get('foo1')).toEqualTypeOf() - expectTypeOf(c.var.foo1).toEqualTypeOf() - return c.json(0) - }) - - new Hono().get('/', mw1, mw2).get('/', (c) => { - expectTypeOf(c.get('foo1')).toEqualTypeOf() - expectTypeOf(c.get('foo2')).toEqualTypeOf() - expectTypeOf(c.var.foo1).toEqualTypeOf() - expectTypeOf(c.var.foo2).toEqualTypeOf() - return c.json(0) - }) - - new Hono().get('/', mw1, mw2, mw3).get('/', (c) => { - expectTypeOf(c.get('foo1')).toEqualTypeOf() - expectTypeOf(c.get('foo2')).toEqualTypeOf() - expectTypeOf(c.get('foo3')).toEqualTypeOf() - expectTypeOf(c.var.foo1).toEqualTypeOf() - expectTypeOf(c.var.foo2).toEqualTypeOf() - expectTypeOf(c.var.foo3).toEqualTypeOf() - return c.json(0) - }) - - new Hono().get('/', mw1, mw2, mw3, mw4).get('/', (c) => { - expectTypeOf(c.get('foo1')).toEqualTypeOf() - expectTypeOf(c.get('foo2')).toEqualTypeOf() - expectTypeOf(c.get('foo3')).toEqualTypeOf() - expectTypeOf(c.get('foo4')).toEqualTypeOf() - expectTypeOf(c.var.foo1).toEqualTypeOf() - expectTypeOf(c.var.foo2).toEqualTypeOf() - expectTypeOf(c.var.foo3).toEqualTypeOf() - expectTypeOf(c.var.foo4).toEqualTypeOf() - return c.json(0) - }) - - new Hono().get('/', mw1, mw2, mw3, mw4, mw5).get('/', (c) => { - expectTypeOf(c.get('foo1')).toEqualTypeOf() - expectTypeOf(c.get('foo2')).toEqualTypeOf() - expectTypeOf(c.get('foo3')).toEqualTypeOf() - expectTypeOf(c.get('foo4')).toEqualTypeOf() - expectTypeOf(c.get('foo5')).toEqualTypeOf() - expectTypeOf(c.var.foo1).toEqualTypeOf() - expectTypeOf(c.var.foo2).toEqualTypeOf() - expectTypeOf(c.var.foo3).toEqualTypeOf() - expectTypeOf(c.var.foo4).toEqualTypeOf() - expectTypeOf(c.var.foo5).toEqualTypeOf() - return c.json(0) - }) - - new Hono().get('/', mw1, mw2, mw3, mw4, mw5, mw6).get('/', (c) => { - expectTypeOf(c.get('foo1')).toEqualTypeOf() - expectTypeOf(c.get('foo2')).toEqualTypeOf() - expectTypeOf(c.get('foo3')).toEqualTypeOf() - expectTypeOf(c.get('foo4')).toEqualTypeOf() - expectTypeOf(c.get('foo5')).toEqualTypeOf() - expectTypeOf(c.get('foo6')).toEqualTypeOf() - expectTypeOf(c.var.foo1).toEqualTypeOf() - expectTypeOf(c.var.foo2).toEqualTypeOf() - expectTypeOf(c.var.foo3).toEqualTypeOf() - expectTypeOf(c.var.foo4).toEqualTypeOf() - expectTypeOf(c.var.foo5).toEqualTypeOf() - expectTypeOf(c.var.foo6).toEqualTypeOf() - return c.json(0) - }) - - new Hono().get('/', mw1, mw2, mw3, mw4, mw5, mw6, mw7).get('/', (c) => { - expectTypeOf(c.get('foo1')).toEqualTypeOf() - expectTypeOf(c.get('foo2')).toEqualTypeOf() - expectTypeOf(c.get('foo3')).toEqualTypeOf() - expectTypeOf(c.get('foo4')).toEqualTypeOf() - expectTypeOf(c.get('foo5')).toEqualTypeOf() - expectTypeOf(c.get('foo6')).toEqualTypeOf() - expectTypeOf(c.get('foo7')).toEqualTypeOf() - expectTypeOf(c.var.foo1).toEqualTypeOf() - expectTypeOf(c.var.foo2).toEqualTypeOf() - expectTypeOf(c.var.foo3).toEqualTypeOf() - expectTypeOf(c.var.foo4).toEqualTypeOf() - expectTypeOf(c.var.foo5).toEqualTypeOf() - expectTypeOf(c.var.foo6).toEqualTypeOf() - expectTypeOf(c.var.foo7).toEqualTypeOf() - return c.json(0) - }) - - new Hono().get('/', mw1, mw2, mw3, mw4, mw5, mw6, mw7, mw8).get('/', (c) => { - expectTypeOf(c.get('foo1')).toEqualTypeOf() - expectTypeOf(c.get('foo2')).toEqualTypeOf() - expectTypeOf(c.get('foo3')).toEqualTypeOf() - expectTypeOf(c.get('foo4')).toEqualTypeOf() - expectTypeOf(c.get('foo5')).toEqualTypeOf() - expectTypeOf(c.get('foo6')).toEqualTypeOf() - expectTypeOf(c.get('foo7')).toEqualTypeOf() - expectTypeOf(c.get('foo8')).toEqualTypeOf() - expectTypeOf(c.var.foo1).toEqualTypeOf() - expectTypeOf(c.var.foo2).toEqualTypeOf() - expectTypeOf(c.var.foo3).toEqualTypeOf() - expectTypeOf(c.var.foo4).toEqualTypeOf() - expectTypeOf(c.var.foo5).toEqualTypeOf() - expectTypeOf(c.var.foo6).toEqualTypeOf() - expectTypeOf(c.var.foo7).toEqualTypeOf() - expectTypeOf(c.var.foo8).toEqualTypeOf() - return c.json(0) - }) - - new Hono().get('/', mw1, mw2, mw3, mw4, mw5, mw6, mw7, mw8, mw9).get('/', (c) => { - expectTypeOf(c.get('foo1')).toEqualTypeOf() - expectTypeOf(c.get('foo2')).toEqualTypeOf() - expectTypeOf(c.get('foo3')).toEqualTypeOf() - expectTypeOf(c.get('foo4')).toEqualTypeOf() - expectTypeOf(c.get('foo5')).toEqualTypeOf() - expectTypeOf(c.get('foo6')).toEqualTypeOf() - expectTypeOf(c.get('foo7')).toEqualTypeOf() - expectTypeOf(c.get('foo8')).toEqualTypeOf() - expectTypeOf(c.get('foo9')).toEqualTypeOf() - expectTypeOf(c.var.foo1).toEqualTypeOf() - expectTypeOf(c.var.foo2).toEqualTypeOf() - expectTypeOf(c.var.foo3).toEqualTypeOf() - expectTypeOf(c.var.foo4).toEqualTypeOf() - expectTypeOf(c.var.foo5).toEqualTypeOf() - expectTypeOf(c.var.foo6).toEqualTypeOf() - expectTypeOf(c.var.foo7).toEqualTypeOf() - expectTypeOf(c.var.foo8).toEqualTypeOf() - expectTypeOf(c.var.foo9).toEqualTypeOf() - return c.json(0) - }) - - new Hono().get('/', mw1, mw2, mw3, mw4, mw5, mw6, mw7, mw8, mw9, mw10).get('/', (c) => { - expectTypeOf(c.get('foo1')).toEqualTypeOf() - expectTypeOf(c.get('foo2')).toEqualTypeOf() - expectTypeOf(c.get('foo3')).toEqualTypeOf() - expectTypeOf(c.get('foo4')).toEqualTypeOf() - expectTypeOf(c.get('foo5')).toEqualTypeOf() - expectTypeOf(c.get('foo6')).toEqualTypeOf() - expectTypeOf(c.get('foo7')).toEqualTypeOf() - expectTypeOf(c.get('foo8')).toEqualTypeOf() - expectTypeOf(c.get('foo9')).toEqualTypeOf() - expectTypeOf(c.get('foo10')).toEqualTypeOf() - expectTypeOf(c.var.foo1).toEqualTypeOf() - expectTypeOf(c.var.foo2).toEqualTypeOf() - expectTypeOf(c.var.foo3).toEqualTypeOf() - expectTypeOf(c.var.foo4).toEqualTypeOf() - expectTypeOf(c.var.foo5).toEqualTypeOf() - expectTypeOf(c.var.foo6).toEqualTypeOf() - expectTypeOf(c.var.foo7).toEqualTypeOf() - expectTypeOf(c.var.foo8).toEqualTypeOf() - expectTypeOf(c.var.foo9).toEqualTypeOf() - expectTypeOf(c.var.foo10).toEqualTypeOf() - return c.json(0) - }) - new Hono().get('/', mw1, mw2, mw3, mw4, mw5, mw6, mw7, mw8, mw9, (c) => { expectTypeOf(c.req.valid('query')).toMatchTypeOf<{ bar1: number @@ -1003,6 +851,390 @@ describe('c.var with chaining - test only types', () => { return c.json(0) }) + + type Env = { + Variables: { + init: number + } + } + + new Hono() + .get('/', mw1, (c) => { + expectTypeOf(c.get('init')).toEqualTypeOf() + expectTypeOf(c.var.init).toEqualTypeOf() + expectTypeOf(c.get('foo1')).toEqualTypeOf() + expectTypeOf(c.var.foo1).toEqualTypeOf() + return c.json(0) + }) + .get('/', (c) => { + expectTypeOf(c.get('init')).toEqualTypeOf() + expectTypeOf(c.var.init).toEqualTypeOf() + // @ts-expect-error foo1 is not typed + c.get('foo1') + // @ts-expect-error foo1 is not typed + c.var.foo1 + return c.json(0) + }) + + new Hono() + .get('/', mw1, mw2, (c) => { + expectTypeOf(c.get('init')).toEqualTypeOf() + expectTypeOf(c.var.init).toEqualTypeOf() + expectTypeOf(c.get('foo1')).toEqualTypeOf() + expectTypeOf(c.var.foo1).toEqualTypeOf() + expectTypeOf(c.get('foo2')).toEqualTypeOf() + expectTypeOf(c.var.foo2).toEqualTypeOf() + return c.json(0) + }) + .get('/', (c) => { + expectTypeOf(c.get('init')).toEqualTypeOf() + expectTypeOf(c.var.init).toEqualTypeOf() + // @ts-expect-error foo1 is not typed + c.get('foo1') + // @ts-expect-error foo1 is not typed + c.var.foo1 + // @ts-expect-error foo2 is not typed + c.get('foo2') + // @ts-expect-error foo2 is not typed + c.var.foo2 + return c.json(0) + }) + + new Hono() + .get('/', mw1, mw2, mw3, (c) => { + expectTypeOf(c.get('init')).toEqualTypeOf() + expectTypeOf(c.var.init).toEqualTypeOf() + expectTypeOf(c.get('foo1')).toEqualTypeOf() + expectTypeOf(c.var.foo1).toEqualTypeOf() + expectTypeOf(c.get('foo2')).toEqualTypeOf() + expectTypeOf(c.var.foo2).toEqualTypeOf() + expectTypeOf(c.get('foo3')).toEqualTypeOf() + expectTypeOf(c.var.foo3).toEqualTypeOf() + return c.json(0) + }) + .get('/', (c) => { + expectTypeOf(c.get('init')).toEqualTypeOf() + expectTypeOf(c.var.init).toEqualTypeOf() + // @ts-expect-error foo1 is not typed + c.get('foo1') + // @ts-expect-error foo1 is not typed + c.var.foo1 + // @ts-expect-error foo2 is not typed + c.get('foo2') + // @ts-expect-error foo2 is not typed + c.var.foo2 + // @ts-expect-error foo3 is not typed + c.get('foo3') + // @ts-expect-error foo3 is not typed + c.var.foo3 + return c.json(0) + }) + + new Hono() + .get('/', mw1, mw2, mw3, mw4, (c) => { + expectTypeOf(c.get('init')).toEqualTypeOf() + expectTypeOf(c.var.init).toEqualTypeOf() + expectTypeOf(c.get('foo1')).toEqualTypeOf() + expectTypeOf(c.var.foo1).toEqualTypeOf() + expectTypeOf(c.get('foo2')).toEqualTypeOf() + expectTypeOf(c.var.foo2).toEqualTypeOf() + expectTypeOf(c.get('foo3')).toEqualTypeOf() + expectTypeOf(c.var.foo3).toEqualTypeOf() + expectTypeOf(c.get('foo4')).toEqualTypeOf() + expectTypeOf(c.var.foo4).toEqualTypeOf() + return c.json(0) + }) + .get('/', (c) => { + expectTypeOf(c.get('init')).toEqualTypeOf() + expectTypeOf(c.var.init).toEqualTypeOf() + // @ts-expect-error foo1 is not typed + c.get('foo1') + // @ts-expect-error foo1 is not typed + c.var.foo1 + // @ts-expect-error foo2 is not typed + c.get('foo2') + // @ts-expect-error foo2 is not typed + c.var.foo2 + // @ts-expect-error foo3 is not typed + c.get('foo3') + // @ts-expect-error foo3 is not typed + c.var.foo3 + // @ts-expect-error foo4 is not typed + c.get('foo4') + // @ts-expect-error foo4 is not typed + c.var.foo4 + return c.json(0) + }) + + new Hono() + .get('/', mw1, mw2, mw3, mw4, mw5, (c) => { + expectTypeOf(c.get('init')).toEqualTypeOf() + expectTypeOf(c.var.init).toEqualTypeOf() + expectTypeOf(c.get('foo1')).toEqualTypeOf() + expectTypeOf(c.var.foo1).toEqualTypeOf() + expectTypeOf(c.get('foo2')).toEqualTypeOf() + expectTypeOf(c.var.foo2).toEqualTypeOf() + expectTypeOf(c.get('foo3')).toEqualTypeOf() + expectTypeOf(c.var.foo3).toEqualTypeOf() + expectTypeOf(c.get('foo4')).toEqualTypeOf() + expectTypeOf(c.var.foo4).toEqualTypeOf() + expectTypeOf(c.get('foo5')).toEqualTypeOf() + expectTypeOf(c.var.foo5).toEqualTypeOf() + return c.json(0) + }) + .get('/', (c) => { + expectTypeOf(c.get('init')).toEqualTypeOf() + expectTypeOf(c.var.init).toEqualTypeOf() + // @ts-expect-error foo1 is not typed + c.get('foo1') + // @ts-expect-error foo1 is not typed + c.var.foo1 + // @ts-expect-error foo2 is not typed + c.get('foo2') + // @ts-expect-error foo2 is not typed + c.var.foo2 + // @ts-expect-error foo3 is not typed + c.get('foo3') + // @ts-expect-error foo3 is not typed + c.var.foo3 + // @ts-expect-error foo4 is not typed + c.get('foo4') + // @ts-expect-error foo4 is not typed + c.var.foo4 + // @ts-expect-error foo5 is not typed + c.get('foo5') + // @ts-expect-error foo5 is not typed + c.var.foo5 + return c.json(0) + }) + + new Hono() + .get('/', mw1, mw2, mw3, mw4, mw5, mw6, (c) => { + expectTypeOf(c.get('init')).toEqualTypeOf() + expectTypeOf(c.var.init).toEqualTypeOf() + expectTypeOf(c.get('foo1')).toEqualTypeOf() + expectTypeOf(c.var.foo1).toEqualTypeOf() + expectTypeOf(c.get('foo2')).toEqualTypeOf() + expectTypeOf(c.var.foo2).toEqualTypeOf() + expectTypeOf(c.get('foo3')).toEqualTypeOf() + expectTypeOf(c.var.foo3).toEqualTypeOf() + expectTypeOf(c.get('foo4')).toEqualTypeOf() + expectTypeOf(c.var.foo4).toEqualTypeOf() + expectTypeOf(c.get('foo5')).toEqualTypeOf() + expectTypeOf(c.var.foo5).toEqualTypeOf() + expectTypeOf(c.get('foo6')).toEqualTypeOf() + expectTypeOf(c.var.foo6).toEqualTypeOf() + return c.json(0) + }) + .get('/', (c) => { + expectTypeOf(c.get('init')).toEqualTypeOf() + expectTypeOf(c.var.init).toEqualTypeOf() + // @ts-expect-error foo1 is not typed + c.get('foo1') + // @ts-expect-error foo1 is not typed + c.var.foo1 + // @ts-expect-error foo2 is not typed + c.get('foo2') + // @ts-expect-error foo2 is not typed + c.var.foo2 + // @ts-expect-error foo3 is not typed + c.get('foo3') + // @ts-expect-error foo3 is not typed + c.var.foo3 + // @ts-expect-error foo4 is not typed + c.get('foo4') + // @ts-expect-error foo4 is not typed + c.var.foo4 + // @ts-expect-error foo5 is not typed + c.get('foo5') + // @ts-expect-error foo5 is not typed + c.var.foo5 + // @ts-expect-error foo6 is not typed + c.get('foo6') + // @ts-expect-error foo6 is not typed + c.var.foo6 + return c.json(0) + }) + + new Hono() + .get('/', mw1, mw2, mw3, mw4, mw5, mw6, mw7, (c) => { + expectTypeOf(c.get('init')).toEqualTypeOf() + expectTypeOf(c.var.init).toEqualTypeOf() + expectTypeOf(c.get('foo1')).toEqualTypeOf() + expectTypeOf(c.var.foo1).toEqualTypeOf() + expectTypeOf(c.get('foo2')).toEqualTypeOf() + expectTypeOf(c.var.foo2).toEqualTypeOf() + expectTypeOf(c.get('foo3')).toEqualTypeOf() + expectTypeOf(c.var.foo3).toEqualTypeOf() + expectTypeOf(c.get('foo4')).toEqualTypeOf() + expectTypeOf(c.var.foo4).toEqualTypeOf() + expectTypeOf(c.get('foo5')).toEqualTypeOf() + expectTypeOf(c.var.foo5).toEqualTypeOf() + expectTypeOf(c.get('foo6')).toEqualTypeOf() + expectTypeOf(c.var.foo6).toEqualTypeOf() + expectTypeOf(c.get('foo7')).toEqualTypeOf() + expectTypeOf(c.var.foo7).toEqualTypeOf() + return c.json(0) + }) + .get('/', (c) => { + expectTypeOf(c.get('init')).toEqualTypeOf() + expectTypeOf(c.var.init).toEqualTypeOf() + // @ts-expect-error foo1 is not typed + c.get('foo1') + // @ts-expect-error foo1 is not typed + c.var.foo1 + // @ts-expect-error foo2 is not typed + c.get('foo2') + // @ts-expect-error foo2 is not typed + c.var.foo2 + // @ts-expect-error foo3 is not typed + c.get('foo3') + // @ts-expect-error foo3 is not typed + c.var.foo3 + // @ts-expect-error foo4 is not typed + c.get('foo4') + // @ts-expect-error foo4 is not typed + c.var.foo4 + // @ts-expect-error foo5 is not typed + c.get('foo5') + // @ts-expect-error foo5 is not typed + c.var.foo5 + // @ts-expect-error foo6 is not typed + c.get('foo6') + // @ts-expect-error foo6 is not typed + c.var.foo6 + // @ts-expect-error foo7 is not typed + c.get('foo7') + // @ts-expect-error foo7 is not typed + c.var.foo7 + return c.json(0) + }) + + new Hono() + .get('/', mw1, mw2, mw3, mw4, mw5, mw6, mw7, mw8, (c) => { + expectTypeOf(c.get('init')).toEqualTypeOf() + expectTypeOf(c.var.init).toEqualTypeOf() + expectTypeOf(c.get('foo1')).toEqualTypeOf() + expectTypeOf(c.var.foo1).toEqualTypeOf() + expectTypeOf(c.get('foo2')).toEqualTypeOf() + expectTypeOf(c.var.foo2).toEqualTypeOf() + expectTypeOf(c.get('foo3')).toEqualTypeOf() + expectTypeOf(c.var.foo3).toEqualTypeOf() + expectTypeOf(c.get('foo4')).toEqualTypeOf() + expectTypeOf(c.var.foo4).toEqualTypeOf() + expectTypeOf(c.get('foo5')).toEqualTypeOf() + expectTypeOf(c.var.foo5).toEqualTypeOf() + expectTypeOf(c.get('foo6')).toEqualTypeOf() + expectTypeOf(c.var.foo6).toEqualTypeOf() + expectTypeOf(c.get('foo7')).toEqualTypeOf() + expectTypeOf(c.var.foo7).toEqualTypeOf() + expectTypeOf(c.get('foo8')).toEqualTypeOf() + expectTypeOf(c.var.foo8).toEqualTypeOf() + return c.json(0) + }) + .get('/', (c) => { + expectTypeOf(c.get('init')).toEqualTypeOf() + expectTypeOf(c.var.init).toEqualTypeOf() + // @ts-expect-error foo1 is not typed + c.get('foo1') + // @ts-expect-error foo1 is not typed + c.var.foo1 + // @ts-expect-error foo2 is not typed + c.get('foo2') + // @ts-expect-error foo2 is not typed + c.var.foo2 + // @ts-expect-error foo3 is not typed + c.get('foo3') + // @ts-expect-error foo3 is not typed + c.var.foo3 + // @ts-expect-error foo4 is not typed + c.get('foo4') + // @ts-expect-error foo4 is not typed + c.var.foo4 + // @ts-expect-error foo5 is not typed + c.get('foo5') + // @ts-expect-error foo5 is not typed + c.var.foo5 + // @ts-expect-error foo6 is not typed + c.get('foo6') + // @ts-expect-error foo6 is not typed + c.var.foo6 + // @ts-expect-error foo7 is not typed + c.get('foo7') + // @ts-expect-error foo7 is not typed + c.var.foo7 + // @ts-expect-error foo8 is not typed + c.get('foo8') + // @ts-expect-error foo8 is not typed + c.var.foo8 + return c.json(0) + }) + + new Hono() + .get('/', mw1, mw2, mw3, mw4, mw5, mw6, mw7, mw8, mw9, (c) => { + expectTypeOf(c.get('init')).toEqualTypeOf() + expectTypeOf(c.var.init).toEqualTypeOf() + expectTypeOf(c.get('foo1')).toEqualTypeOf() + expectTypeOf(c.var.foo1).toEqualTypeOf() + expectTypeOf(c.get('foo2')).toEqualTypeOf() + expectTypeOf(c.var.foo2).toEqualTypeOf() + expectTypeOf(c.get('foo3')).toEqualTypeOf() + expectTypeOf(c.var.foo3).toEqualTypeOf() + expectTypeOf(c.get('foo4')).toEqualTypeOf() + expectTypeOf(c.var.foo4).toEqualTypeOf() + expectTypeOf(c.get('foo5')).toEqualTypeOf() + expectTypeOf(c.var.foo5).toEqualTypeOf() + expectTypeOf(c.get('foo6')).toEqualTypeOf() + expectTypeOf(c.var.foo6).toEqualTypeOf() + expectTypeOf(c.get('foo7')).toEqualTypeOf() + expectTypeOf(c.var.foo7).toEqualTypeOf() + expectTypeOf(c.get('foo8')).toEqualTypeOf() + expectTypeOf(c.var.foo8).toEqualTypeOf() + expectTypeOf(c.get('foo9')).toEqualTypeOf() + expectTypeOf(c.var.foo9).toEqualTypeOf() + return c.json(0) + }) + .get('/', (c) => { + expectTypeOf(c.get('init')).toEqualTypeOf() + expectTypeOf(c.var.init).toEqualTypeOf() + // @ts-expect-error foo1 is not typed + c.get('foo1') + // @ts-expect-error foo1 is not typed + c.var.foo1 + // @ts-expect-error foo2 is not typed + c.get('foo2') + // @ts-expect-error foo2 is not typed + c.var.foo2 + // @ts-expect-error foo3 is not typed + c.get('foo3') + // @ts-expect-error foo3 is not typed + c.var.foo3 + // @ts-expect-error foo4 is not typed + c.get('foo4') + // @ts-expect-error foo4 is not typed + c.var.foo4 + // @ts-expect-error foo5 is not typed + c.get('foo5') + // @ts-expect-error foo5 is not typed + c.var.foo5 + // @ts-expect-error foo6 is not typed + c.get('foo6') + // @ts-expect-error foo6 is not typed + c.var.foo6 + // @ts-expect-error foo7 is not typed + c.get('foo7') + // @ts-expect-error foo7 is not typed + c.var.foo7 + // @ts-expect-error foo8 is not typed + c.get('foo8') + // @ts-expect-error foo8 is not typed + c.var.foo8 + // @ts-expect-error foo9 is not typed + c.get('foo9') + // @ts-expect-error foo9 is not typed + c.var.foo9 + return c.json(0) + }) }) }) diff --git a/src/types.ts b/src/types.ts index df23cba4e..aa554ef3b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -394,11 +394,7 @@ export interface HandlerInterface< >( path: P, handler: H - ): Hono< - IntersectNonAnyTypes<[E, E2]>, - S & ToSchema, I['in'], MergeTypedResponseData>, - BasePath - > + ): Hono, I['in'], MergeTypedResponseData>, BasePath> // app.get(path, handler x2) < @@ -412,11 +408,7 @@ export interface HandlerInterface< >( path: P, ...handlers: [H, H] - ): Hono< - IntersectNonAnyTypes<[E, E2, E3]>, - S & ToSchema, I2['in'], MergeTypedResponseData>, - BasePath - > + ): Hono, I2['in'], MergeTypedResponseData>, BasePath> // app.get(path, handler x3) < @@ -432,11 +424,7 @@ export interface HandlerInterface< >( path: P, ...handlers: [H, H, H] - ): Hono< - IntersectNonAnyTypes<[E, E2, E3, E4]>, - S & ToSchema, I3['in'], MergeTypedResponseData>, - BasePath - > + ): Hono, I3['in'], MergeTypedResponseData>, BasePath> // app.get(path, handler x4) < @@ -459,11 +447,7 @@ export interface HandlerInterface< H, H ] - ): Hono< - IntersectNonAnyTypes<[E, E2, E3, E4, E5]>, - S & ToSchema, I4['in'], MergeTypedResponseData>, - BasePath - > + ): Hono, I4['in'], MergeTypedResponseData>, BasePath> // app.get(path, handler x5) < @@ -489,11 +473,7 @@ export interface HandlerInterface< H, H ] - ): Hono< - IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>, - S & ToSchema, I5['in'], MergeTypedResponseData>, - BasePath - > + ): Hono, I5['in'], MergeTypedResponseData>, BasePath> // app.get(path, handler x6) < @@ -522,11 +502,7 @@ export interface HandlerInterface< H, H ] - ): Hono< - IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>, - S & ToSchema, I6['in'], MergeTypedResponseData>, - BasePath - > + ): Hono, I6['in'], MergeTypedResponseData>, BasePath> // app.get(path, handler x7) < @@ -558,11 +534,7 @@ export interface HandlerInterface< H, H ] - ): Hono< - IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>, - S & ToSchema, I7['in'], MergeTypedResponseData>, - BasePath - > + ): Hono, I7['in'], MergeTypedResponseData>, BasePath> // app.get(path, handler x8) < @@ -597,11 +569,7 @@ export interface HandlerInterface< H, H ] - ): Hono< - IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>, - S & ToSchema, I8['in'], MergeTypedResponseData>, - BasePath - > + ): Hono, I8['in'], MergeTypedResponseData>, BasePath> // app.get(path, handler x9) < @@ -639,11 +607,7 @@ export interface HandlerInterface< H, H ] - ): Hono< - IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10]>, - S & ToSchema, I9['in'], MergeTypedResponseData>, - BasePath - > + ): Hono, I9['in'], MergeTypedResponseData>, BasePath> // app.get(path, handler x10) < @@ -685,7 +649,7 @@ export interface HandlerInterface< H ] ): Hono< - IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10, E11]>, + E, S & ToSchema, I10['in'], MergeTypedResponseData>, BasePath >