fix(types): remove DOM type dependencies from ClientResponse and request method#4768
Open
YevheniiKotyrlo wants to merge 1 commit intohonojs:mainfrom
Open
fix(types): remove DOM type dependencies from ClientResponse and request method#4768YevheniiKotyrlo wants to merge 1 commit intohonojs:mainfrom
YevheniiKotyrlo wants to merge 1 commit intohonojs:mainfrom
Conversation
…est method 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 honojs#3750 Related: honojs#1200, honojs#3312
Contributor
BarryThePenguin
left a comment
There was a problem hiding this comment.
I have a local branch which disables lib: dom. That is a much larger change, but I think this is a good start and is the right direction to take 👍🏻
Author
Happy to apply all reviewer changes for this quick fix to pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
extends globalThis.ResponsefromClientResponseinterface insrc/client/types.ts, addingredirected,type, andbytes()properties inline so the interface remains structurally compatible withResponseRequestInfo | URLwithRequest | string | URLinHono.request()method signature insrc/hono-base.ts(semantically identical sinceRequestInfo = Request | stringin DOM lib)Motivation
Hono's type declarations depend on DOM-only types (
globalThis.Response,RequestInfo) that are unavailable in non-DOM TypeScript environments (e.g. Bun withtypes: ["bun"], Node without DOM lib). Projects usingskipLibCheck: falsein these environments hitTS2304errors when importing from hono.Related issues: #1200, #3312, #3750
Changes
src/client/types.tsClientResponsealready redeclares allResponsemembers inline. Removing theextends globalThis.Responseclause and adding three previously-inherited properties (redirected,type,bytes()) makes the interface self-contained and structurally compatible withResponsewithout requiring DOM types.src/hono-base.tsRequestInfois defined asRequest | stringinlib.dom.d.ts. Expanding it inline toRequest | string | URLremoves the DOM dependency while being semantically identical.Checklist
vitest --run— 144/144 files, 4097/4097 tests pass)bun run format:fix && bun run lint:fix(0 errors, 50 warnings — identical to baseline)tsc --noEmit— 0 errorsbun run build— CJS + ESM + declarations all build successfullyeditorconfig-checker— passCloses #3750