fix(types): remove DOM type dependencies from ClientResponse and request method#4768
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
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 👍🏻
Happy to apply all reviewer changes for this quick fix to pass |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4768 +/- ##
=======================================
Coverage 91.48% 91.48%
=======================================
Files 177 177
Lines 11551 11551
Branches 3353 3352 -1
=======================================
Hits 10567 10567
Misses 983 983
Partials 1 1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
BarryThePenguin
left a comment
There was a problem hiding this comment.
Let's start with this, it's a pretty minor change 👍🏻
|
I also think removing DOM type dependencies is a good idea. Thanks! |
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