diff --git a/src/request.ts b/src/request.ts index 69bc3084..ce2148c5 100644 --- a/src/request.ts +++ b/src/request.ts @@ -73,22 +73,24 @@ export class HonoRequest

{ return null } - query(key: string): string | undefined - query(): Record - query(key?: string) { - return getQueryParam(this.url, key) + query>(): T + query, K = keyof T>( + key: K + ): K extends string ? T[K] : undefined + query>(key?: keyof T) { + return getQueryParam(this.url, key as string) } - queries(key: string): string[] | undefined - queries(): Record - queries(key?: string) { - return getQueryParams(this.url, key) + queries>(): T + queries>(key: keyof T): string[] + queries>(key?: keyof T) { + return getQueryParams(this.url, key as string) } - header(name: string): string | undefined - header(): Record - header(name?: string) { - if (name) return this.raw.headers.get(name.toLowerCase()) ?? undefined + header>(): T + header>(name: keyof T): string + header>(name?: keyof T) { + if (name) return this.raw.headers.get((name as string).toLowerCase()) ?? undefined const headerData: Record = {} this.raw.headers.forEach((value, key) => {