From 9cb6b37fa3484eda479f9fb5f9c16757009c841a Mon Sep 17 00:00:00 2001 From: Yusuke Wada Date: Wed, 13 Sep 2023 08:57:52 +0900 Subject: [PATCH] fix(types): fix the type error in `MiddlewareHandlerInterface` (#1449) * fix(types): fix the type error in `MiddlewareHandlerInterface` * denoify --- deno_dist/hono-base.ts | 3 ++- deno_dist/types.ts | 11 +++++------ src/hono-base.ts | 3 ++- src/hono.test.ts | 11 +++++++++++ src/types.ts | 11 +++++------ 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/deno_dist/hono-base.ts b/deno_dist/hono-base.ts index 61996784f..9e2d858cc 100644 --- a/deno_dist/hono-base.ts +++ b/deno_dist/hono-base.ts @@ -109,7 +109,8 @@ class Hono< } // Implementation of app.use(...handlers[]) or app.get(path, ...handlers[]) - this.use = (arg1: string | MiddlewareHandler, ...handlers: MiddlewareHandler[]) => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + this.use = (arg1: string | MiddlewareHandler, ...handlers: MiddlewareHandler[]) => { if (typeof arg1 === 'string') { this.path = arg1 } else { diff --git a/deno_dist/types.ts b/deno_dist/types.ts index 2f77b3286..73edc8241 100644 --- a/deno_dist/types.ts +++ b/deno_dist/types.ts @@ -42,7 +42,7 @@ export type Handler< R extends HandlerResponse = any > = (c: Context, next: Next) => R -export type MiddlewareHandler = ( +export type MiddlewareHandler = ( c: Context, next: Next ) => Promise @@ -296,11 +296,10 @@ export interface MiddlewareHandlerInterface< //// app.get(...handlers[]) (...handlers: MiddlewareHandler>>[]): Hono //// app.get(path, ...handlers[]) -

(path: P, ...handlers: MiddlewareHandler>[]): Hono< - E, - S, - BasePath - > +

( + path: P, + ...handlers: MiddlewareHandler>[] + ): Hono } //////////////////////////////////////// diff --git a/src/hono-base.ts b/src/hono-base.ts index 64dd9d875..e4a31b74e 100644 --- a/src/hono-base.ts +++ b/src/hono-base.ts @@ -109,7 +109,8 @@ class Hono< } // Implementation of app.use(...handlers[]) or app.get(path, ...handlers[]) - this.use = (arg1: string | MiddlewareHandler, ...handlers: MiddlewareHandler[]) => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + this.use = (arg1: string | MiddlewareHandler, ...handlers: MiddlewareHandler[]) => { if (typeof arg1 === 'string') { this.path = arg1 } else { diff --git a/src/hono.test.ts b/src/hono.test.ts index e096527b3..1b9a6cc6d 100644 --- a/src/hono.test.ts +++ b/src/hono.test.ts @@ -2660,4 +2660,15 @@ describe('c.var - with testing types', () => { }) }).toThrow() }) + + it('Should not throw a type error', (c) => { + const app = new Hono<{ + Bindings: { + TOKEN: string + } + }>() + app.get('/', poweredBy(), async (c) => { + type verify = Expect> + }) + }) }) diff --git a/src/types.ts b/src/types.ts index 17f1cd7c9..4bcc88dea 100644 --- a/src/types.ts +++ b/src/types.ts @@ -42,7 +42,7 @@ export type Handler< R extends HandlerResponse = any > = (c: Context, next: Next) => R -export type MiddlewareHandler = ( +export type MiddlewareHandler = ( c: Context, next: Next ) => Promise @@ -296,11 +296,10 @@ export interface MiddlewareHandlerInterface< //// app.get(...handlers[]) (...handlers: MiddlewareHandler>>[]): Hono //// app.get(path, ...handlers[]) -

(path: P, ...handlers: MiddlewareHandler>[]): Hono< - E, - S, - BasePath - > +

( + path: P, + ...handlers: MiddlewareHandler>[] + ): Hono } ////////////////////////////////////////