fix(type): change the type definition of `req` in Context (#658)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Yusuke Wada · committed by GitHub · parent b82547f · Browse files · 7 files·+23 added−43 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+23 added−43 removed
- other:+23 added−43 removed
Provenance
- Commit
d3a6f80- Tree
0360e5d- Author
Yusuke Wada <yusuke@kamawada.com>- Committer
GitHub <noreply@github.com>- Parent
b82547f
7 files changed+23 added−43 removed
modified:deno_dist/utils/encode.ts+1 added-1 removed
11234572 unmodified linesimport { Buffer } from "https://deno.land/std@0.162.0/node/buffer.ts";import { Buffer } from "https://deno.land/std@0.163.0/node/buffer.ts";export const encodeBase64 = (str: string): string => { if (str === null) { throw new TypeError('1st argument of "encodeBase64" should not be null.') }72 unmodified linesmodified:deno_dist/context.ts+3 added-3 removed
10 unmodified lines11 12 export class Context<13 P extends string = string,14 E extends Partial<Environment> = Environment,15- S extends Partial<Schema> | unknown = Schema15+ S extends Partial<Schema> = Schema16 > {17- req: Request<P, S extends Schema ? SchemaToProp<S> : any>17+ req: Request<P, S extends Schema ? SchemaToProp<S> : S>18 env: E['Bindings']19 finalized: boolean20 error: Error | undefined = undefined21 12 unmodified lines34 executionCtx: FetchEvent | ExecutionContext | undefined = undefined,35 notFoundHandler: NotFoundHandler<E> = () => new Response()36 ) {37 this._executionCtx = executionCtx38- this.req = req as Request<P, S extends Schema ? SchemaToProp<S> : any>38+ this.req = req as Request<P, S extends Schema ? SchemaToProp<S> : S>39 this.env = env || ({} as Bindings)40 41 this.notFoundHandler = notFoundHandler42 this.finalized = false185 unmodified linesmodified:deno_dist/hono.ts+7 added-7 removed
112 unmodified lines113 route(path: string, app?: Hono<any>) {114 this._tempPath = path115 if (app) {116 app.routes.map((r) => {117- this.addRoute(r.method, r.path, r.handler as unknown as Handler<P, E>)117+ this.addRoute(r.method, r.path, r.handler as unknown as Handler<P, E, S>)118 })119 this._tempPath = ''120 }121 return this59 unmodified lines181 private matchRoute(method: string, path: string) {182 return this.router.match(method, path)183 }184 185- private handleError(err: unknown, c: Context<string, E, S>) {185+ private handleError(err: unknown, c: Context<string, E>) {186 if (err instanceof Error) {187 return this.errorHandler(err, c)188 }189 throw err18 unmodified lines208 let res: ReturnType<Handler<P>>209 210 try {211 res = handler(c, async () => {})212- if (!res) return this.notFoundHandler(c)212+ if (!res) return this.notFoundHandler(c as Context)213 } catch (err) {214- return this.handleError(err, c)214+ return this.handleError(err, c as Context)215 }216 217 if (res instanceof Response) return res218 1 unmodified line220 let awaited: Response | undefined | void221 try {222 awaited = await res223 if (!awaited) {224- return this.notFoundHandler(c)224+ return this.notFoundHandler(c as Context)225 }226 } catch (err) {227- return this.handleError(err, c)227+ return this.handleError(err, c as Context)228 }229 return awaited230 })()231 }11 unmodified lines243 )244 }245 return context.res246 } catch (err) {247- return this.handleError(err, c)247+ return this.handleError(err, c as Context)248 }249 })()250 }251 13 unmodified linesmodified:deno_dist/types.ts+1 added-11 removed
71 unmodified lines727374757677787980818283848586767778798071 unmodified lines : E : E extends Partial<Schema> ? Partial<Environment> : Environment, P extends Partial<Schema> ? P : E extends Partial<Schema> ? P extends Partial<Environment> ? E extends Partial<Environment> ? unknown : E : unknown : S extends Partial<Schema> ? S : never S extends Schema ? S : P extends Schema ? P : E extends Schema ? E : any >, next: Next ): Response | Promise<Response | undefined | void>}modified:src/context.ts+3 added-3 removed
10 unmodified lines11 12 export class Context<13 P extends string = string,14 E extends Partial<Environment> = Environment,15- S extends Partial<Schema> | unknown = Schema15+ S extends Partial<Schema> = Schema16 > {17- req: Request<P, S extends Schema ? SchemaToProp<S> : any>17+ req: Request<P, S extends Schema ? SchemaToProp<S> : S>18 env: E['Bindings']19 finalized: boolean20 error: Error | undefined = undefined21 12 unmodified lines34 executionCtx: FetchEvent | ExecutionContext | undefined = undefined,35 notFoundHandler: NotFoundHandler<E> = () => new Response()36 ) {37 this._executionCtx = executionCtx38- this.req = req as Request<P, S extends Schema ? SchemaToProp<S> : any>38+ this.req = req as Request<P, S extends Schema ? SchemaToProp<S> : S>39 this.env = env || ({} as Bindings)40 41 this.notFoundHandler = notFoundHandler42 this.finalized = false185 unmodified linesmodified:src/hono.ts+7 added-7 removed
112 unmodified lines113 route(path: string, app?: Hono<any>) {114 this._tempPath = path115 if (app) {116 app.routes.map((r) => {117- this.addRoute(r.method, r.path, r.handler as unknown as Handler<P, E>)117+ this.addRoute(r.method, r.path, r.handler as unknown as Handler<P, E, S>)118 })119 this._tempPath = ''120 }121 return this59 unmodified lines181 private matchRoute(method: string, path: string) {182 return this.router.match(method, path)183 }184 185- private handleError(err: unknown, c: Context<string, E, S>) {185+ private handleError(err: unknown, c: Context<string, E>) {186 if (err instanceof Error) {187 return this.errorHandler(err, c)188 }189 throw err18 unmodified lines208 let res: ReturnType<Handler<P>>209 210 try {211 res = handler(c, async () => {})212- if (!res) return this.notFoundHandler(c)212+ if (!res) return this.notFoundHandler(c as Context)213 } catch (err) {214- return this.handleError(err, c)214+ return this.handleError(err, c as Context)215 }216 217 if (res instanceof Response) return res218 1 unmodified line220 let awaited: Response | undefined | void221 try {222 awaited = await res223 if (!awaited) {224- return this.notFoundHandler(c)224+ return this.notFoundHandler(c as Context)225 }226 } catch (err) {227- return this.handleError(err, c)227+ return this.handleError(err, c as Context)228 }229 return awaited230 })()231 }11 unmodified lines243 )244 }245 return context.res246 } catch (err) {247- return this.handleError(err, c)247+ return this.handleError(err, c as Context)248 }249 })()250 }251 13 unmodified linesmodified:src/types.ts+1 added-11 removed
71 unmodified lines72 : E73 : E extends Partial<Schema>74 ? Partial<Environment>75 : Environment,76- P extends Partial<Schema>77- ? P78- : E extends Partial<Schema>79- ? P extends Partial<Environment>80- ? E extends Partial<Environment>81- ? unknown82- : E83- : unknown84- : S extends Partial<Schema>85- ? S86- : never76+ S extends Schema ? S : P extends Schema ? P : E extends Schema ? E : any77 >,78 next: Next79 ): Response | Promise<Response | undefined | void>80 }