Skip to content

Comments

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

Open
YevheniiKotyrlo wants to merge 1 commit intohonojs:mainfrom
YevheniiKotyrlo:fix/remove-dom-type-dependencies
Open

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

Conversation

@YevheniiKotyrlo
Copy link

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

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'.

2 participants