Skip to content
Myr

fix(types): remove DOM type dependencies from ClientResponse and request method (#4768)

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

Remove `extends globalThis.Response` from ClientResponse interface and replace `RequestInfo | URL` with `Request | string | URL` in the Hono.request() method signature. These changes make hono's type declarations self-contained without requiring DOM lib types (lib.dom.d.ts), enabling projects that use `skipLibCheck: false` in non-DOM environments (Bun, Node without DOM lib) to compile without errors. Changes: - ClientResponse: Remove `extends globalThis.Response`, add `redirected`, `type`, and `bytes()` properties inline so the interface remains structurally compatible with Response - Hono.request(): Replace `RequestInfo | URL` with `Request | string | URL` (semantically identical since RequestInfo = Request | string in DOM lib) Closes #3750 Related: #1200, #3312

authored by YevheniiKotyrlo · committed by GitHub · parent b1df304 · Browse files · 2 files+5 added−3 removed
This commit

State

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

Diff stats

2 files+5 added−3 removed

  • other:+5 added−3 removed

2 files+5 added−3 removed

modified:src/client/types.ts+4 added-2 removed
127 unmodified lines
128export interface ClientResponse<129 T,130 U extends number = StatusCode,131 F extends ResponseFormat = ResponseFormat,132>133 extends globalThis.Response {132> {133 readonly body: ReadableStream | null134 readonly bodyUsed: boolean135 ok: U extends SuccessStatusCode136 ? true137 : U extends Exclude<StatusCode, SuccessStatusCode>138 ? false139 : boolean140 redirected: boolean141 status: U142 statusText: string143 type: 'basic' | 'cors' | 'default' | 'error' | 'opaque' | 'opaqueredirect'144 headers: Headers145 url: string146 redirect(url: string, status: number): Response147 clone(): Response148 bytes(): Promise<Uint8Array<ArrayBuffer>>149 json(): F extends 'text' ? Promise<never> : F extends 'json' ? Promise<T> : Promise<unknown>150 text(): F extends 'text' ? (T extends string ? Promise<T> : Promise<never>) : Promise<string>151 blob(): Promise<Blob>152 formData(): Promise<FormData>
209 unmodified lines
modified:src/hono-base.ts+1 added-1 removed
489 unmodified lines
490 * ```491 * @see https://hono.dev/docs/api/hono#request492 */493 request = (494 input: RequestInfo | URL,494 input: Request | string | URL,495 requestInit?: RequestInit,496 Env?: E['Bindings'] | {},497 executionCtx?: ExecutionContext498 ): Response | Promise<Response> => {
41 unmodified lines