Skip to content

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

Merged
yusukebe merged 1 commit intohonojs:mainfrom
YevheniiKotyrlo:fix/remove-dom-type-dependencies
Feb 26, 2026
Merged

fix(types): remove DOM type dependencies from ClientResponse and request method#4768
yusukebe merged 1 commit intohonojs:mainfrom
YevheniiKotyrlo:fix/remove-dom-type-dependencies

Conversation

@YevheniiKotyrlo
Copy link
Copy Markdown
Contributor

Summary

  • Remove extends globalThis.Response from ClientResponse interface in src/client/types.ts, adding redirected, type, and bytes() properties inline so the interface remains structurally compatible with Response
  • Replace RequestInfo | URL with Request | string | URL in Hono.request() method signature in src/hono-base.ts (semantically identical since RequestInfo = Request | string in 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 with types: ["bun"], Node without DOM lib). Projects using skipLibCheck: false in these environments hit TS2304 errors when importing from hono.

Related issues: #1200, #3312, #3750

Changes

src/client/types.ts

ClientResponse already redeclares all Response members inline. Removing the extends globalThis.Response clause and adding three previously-inherited properties (redirected, type, bytes()) makes the interface self-contained and structurally compatible with Response without requiring DOM types.

src/hono-base.ts

RequestInfo is defined as Request | string in lib.dom.d.ts. Expanding it inline to Request | string | URL removes the DOM dependency while being semantically identical.

Checklist

  • Added tests (no new runtime behavior; existing 4097 tests all pass)
  • Ran tests (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 errors
  • bun run build — CJS + ESM + declarations all build successfully
  • editorconfig-checker — pass

Closes #3750

…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
Copy link
Copy Markdown
Contributor

@BarryThePenguin BarryThePenguin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 👍🏻

@YevheniiKotyrlo
Copy link
Copy Markdown
Contributor Author

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
Copy link
Copy Markdown

codecov Bot commented Feb 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.48%. Comparing base (b1df304) to head (ae74f2c).
⚠️ Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@BarryThePenguin BarryThePenguin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's start with this, it's a pretty minor change 👍🏻

Copy link
Copy Markdown
Member

@yusukebe yusukebe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@yusukebe
Copy link
Copy Markdown
Member

Hi @YevheniiKotyrlo

I also think removing DOM type dependencies is a good idea. Thanks!

@yusukebe yusukebe merged commit eb9c112 into honojs:main Feb 26, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Type 'ClientResponse<T, U, F>' is not assignable to type 'void | Response'.

3 participants