Skip to content
Myr

fix(types): fix the type error in `MiddlewareHandlerInterface` (#1449)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* fix(types): fix the type error in `MiddlewareHandlerInterface` * denoify

authored by Yusuke Wada · committed by GitHub · parent 00af2a5 · Browse files · 5 files+25 added−14 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+25 added−14 removed

  • tests:+11 added−0 removed
  • other:+14 added−14 removed

5 files+25 added−14 removed

modified:deno_dist/hono-base.ts+2 added-1 removed
107 unmodified lines
108 return this as any109 }110111 // Implementation of app.use(...handlers[]) or app.get(path, ...handlers[])112 // eslint-disable-next-line @typescript-eslint/no-explicit-any112 this.use = (arg1: string | MiddlewareHandler, ...handlers: MiddlewareHandler[]) => {113 this.use = (arg1: string | MiddlewareHandler<any>, ...handlers: MiddlewareHandler<any>[]) => {114 if (typeof arg1 === 'string') {115 this.path = arg1116 } else {117 handlers.unshift(arg1)
288 unmodified lines
modified:deno_dist/types.ts+5 added-6 removed
40 unmodified lines
41 I extends Input = Input,42 R extends HandlerResponse<any> = any43> = (c: Context<E, P, I>, next: Next) => R4445export type MiddlewareHandler<E extends Env = any, P extends string = any, I extends Input = {}> = (45export type MiddlewareHandler<E extends Env = {}, P extends string = any, I extends Input = {}> = (46 c: Context<E, P, I>,47 next: Next48) => Promise<Response | void>49
245 unmodified lines
295> {296 //// app.get(...handlers[])297 (...handlers: MiddlewareHandler<E, MergePath<BasePath, ExtractKey<S>>>[]): Hono<E, S, BasePath>298 //// app.get(path, ...handlers[])299 <P extends string>(path: P, ...handlers: MiddlewareHandler<E, MergePath<BasePath, P>>[]): Hono<300 E,301 S,302 BasePath303 >299 <P extends string, E2 extends Env = E>(300 path: P,301 ...handlers: MiddlewareHandler<E2, MergePath<BasePath, P>>[]302 ): Hono<E, S, BasePath>303}304305////////////////////////////////////////306////// //////
274 unmodified lines
modified:src/hono-base.ts+2 added-1 removed
107 unmodified lines
108 return this as any109 }110111 // Implementation of app.use(...handlers[]) or app.get(path, ...handlers[])112 // eslint-disable-next-line @typescript-eslint/no-explicit-any112 this.use = (arg1: string | MiddlewareHandler, ...handlers: MiddlewareHandler[]) => {113 this.use = (arg1: string | MiddlewareHandler<any>, ...handlers: MiddlewareHandler<any>[]) => {114 if (typeof arg1 === 'string') {115 this.path = arg1116 } else {117 handlers.unshift(arg1)
288 unmodified lines
modified:src/hono.test.ts+11 added
2658 unmodified lines
2659 return c.text(c.var.echo('hello'))2660 })2661 }).toThrow()2662 })26632664 it('Should not throw a type error', (c) => {2665 const app = new Hono<{2666 Bindings: {2667 TOKEN: string2668 }2669 }>()2670 app.get('/', poweredBy(), async (c) => {2671 type verify = Expect<Equal<string, typeof c.env.TOKEN>>2672 })2673 })2674})
modified:src/types.ts+5 added-6 removed
40 unmodified lines
41 I extends Input = Input,42 R extends HandlerResponse<any> = any43> = (c: Context<E, P, I>, next: Next) => R4445export type MiddlewareHandler<E extends Env = any, P extends string = any, I extends Input = {}> = (45export type MiddlewareHandler<E extends Env = {}, P extends string = any, I extends Input = {}> = (46 c: Context<E, P, I>,47 next: Next48) => Promise<Response | void>49
245 unmodified lines
295> {296 //// app.get(...handlers[])297 (...handlers: MiddlewareHandler<E, MergePath<BasePath, ExtractKey<S>>>[]): Hono<E, S, BasePath>298 //// app.get(path, ...handlers[])299 <P extends string>(path: P, ...handlers: MiddlewareHandler<E, MergePath<BasePath, P>>[]): Hono<300 E,301 S,302 BasePath303 >299 <P extends string, E2 extends Env = E>(300 path: P,301 ...handlers: MiddlewareHandler<E2, MergePath<BasePath, P>>[]302 ): Hono<E, S, BasePath>303}304305////////////////////////////////////////306////// //////
274 unmodified lines