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
Provenance
- Commit
9cb6b37- Tree
f241c48- Author
Yusuke Wada <yusuke@kamawada.com>- Committer
GitHub <noreply@github.com>- Parent
00af2a5
5 files changed+25 added−14 removed
modified:deno_dist/hono-base.ts+2 added-1 removed
107 unmodified lines108 return this as any109 }110 111 // 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 linesmodified:deno_dist/types.ts+5 added-6 removed
40 unmodified lines41 I extends Input = Input,42 R extends HandlerResponse<any> = any43 > = (c: Context<E, P, I>, next: Next) => R44 45-export type MiddlewareHandler<E extends Env = any, P extends string = any, I extends Input = {}> = (45+export 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 lines295 > {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 }304 305 ////////////////////////////////////////306 ////// //////274 unmodified linesmodified:src/hono-base.ts+2 added-1 removed
107 unmodified lines108 return this as any109 }110 111 // 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 linesmodified:src/hono.test.ts+11 added
2658 unmodified lines2659 return c.text(c.var.echo('hello'))2660 })2661 }).toThrow()2662 })2663+2664+ 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 lines41 I extends Input = Input,42 R extends HandlerResponse<any> = any43 > = (c: Context<E, P, I>, next: Next) => R44 45-export type MiddlewareHandler<E extends Env = any, P extends string = any, I extends Input = {}> = (45+export 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 lines295 > {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 }304 305 ////////////////////////////////////////306 ////// //////274 unmodified lines