You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(types): make toNodeHandler() assignable to http1 and http2 servers - #368
toNodeHandler() returned NodeHttpHandler & AdapterMeta, a union of the http1 and http2 handler types, which is not assignable to the request listener of node:http, node:https or node:http2. The function it returns takes NodeServerRequest / NodeServerResponse and handles both protocols, so the return type is now NodeHttp1Handler & NodeHttp2Handler & AdapterMeta.
This is a type-only change:
The converted handler needs no cast, it already satisfies both signatures.
The toFetchHandler() round trip returns the original __nodeHandler, which is typed as the union, so that branch has one cast. The intersection is optimistic there if the original handler was written for a single protocol.
The as NodeHttp1Handler casts on toNodeHandler() results in the tests are removed.
test/types.test-d.ts asserts the result extends both request listener types.
Verification
A standalone tsc --strict check passing the result to http.createServer, https.createServer, http2.createServer and http2.createSecureServer passes with this change and reports 6 errors without it.
Not run locally: pnpm lint, pnpm typecheck and the vitest suite. Relying on CI for those.
Summary by CodeRabbit
New Features
toNodeHandler is now typed for use with both HTTP/1 and HTTP/2 servers, including node:http, node:https, and node:http2.
The handler can be passed directly to Node server creation without additional type casts.
No actionable comments were generated in the recent review.
Walkthrough
toNodeHandler now declares a return type compatible with both HTTP/1 and HTTP/2 handlers. Tests check that the result can be passed directly to Node server APIs and that its type is assignable to both protocol listener types.
Changes: Node handler protocol typing
Layer / File(s)
Summary
Combined protocol return type src/adapters/_node/adapter.ts
toNodeHandler returns the intersection of the HTTP/1 and HTTP/2 handler types, including when it returns an existing __nodeHandler.
h3js/srvx#310: Changes the handler stored by toFetchHandler, which is returned by toNodeHandler on a round trip.
Merge Risk: Minimal · up to 50b7d
This change only adjusts TypeScript types so toNodeHandler() results can be passed to node:http, node:https and node:http2 servers without a cast. Runtime behavior is unchanged. The known caveat that round-tripped single-protocol handlers are typed optimistically is a stated tradeoff, so no merge-blocking risk remains.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title names the main change: the return type of toNodeHandler() is widened so the handler is assignable to both HTTP/1 and HTTP/2 request listeners. The raw summary and objectives confirm this is …
Linked Issues check
Issue #367 requires that the return type of toNodeHandler() be assignable to the request listeners of node:http, node:https and node:http2 servers without a cast. At the reviewed head, `src/ad…
Out of Scope Changes check
All changed hunks relate to #367. The return-type change and its JSDoc note are in src/adapters/_node/adapter.ts. The NodeHttp1Handler/NodeHttp2Handler imports support the new return type. The r…
Full details: Title check
Explanation
The title names the main change: the return type of toNodeHandler() is widened so the handler is assignable to both HTTP/1 and HTTP/2 request listeners. The raw summary and objectives confirm this is a type-only change to toNodeHandler(), with matching test updates that remove casts and add type assertions. The conventional 'fix(types):' prefix matches the type-only nature of the change.
Full details: Linked Issues check
Explanation
Issue #367 requires that the return type of toNodeHandler() be assignable to the request listeners of node:http, node:https and node:http2 servers without a cast. At the reviewed head, src/adapters/_node/adapter.ts changes the return type from NodeHttpHandler & AdapterMeta to NodeHttp1Handler & NodeHttp2Handler & AdapterMeta. The toFetchHandler() round-trip branch returns handler.__nodeHandler with a cast to the same intersection, which matches the caveat in #367. The casts on toNodeHandler() results in the tests are removed (per the PR summary). test/types.test-d.ts adds type assertions that ReturnType<typeof toNodeHandler> extends RequestListener (node:http) and an Http2ServerRequest/Http2ServerResponse listener signature (node:http2). I read the diff only. I did not run tsc, pnpm typecheck or Vitest. The author also did not run them locally. The type-level evidence supports the requirement.
Full details: Out of Scope Changes check
Explanation
All changed hunks relate to #367. The return-type change and its JSDoc note are in src/adapters/_node/adapter.ts. The NodeHttp1Handler/NodeHttp2Handler imports support the new return type. The round-trip cast carries the caveat named in #367. The test files remove casts that the new return type makes unnecessary, and test/types.test-d.ts adds assertions for the new type. No unrelated behavior change appears in the diff. The runtime conversion path is unchanged.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
A rabbit checks the types with care, HTTP/1 and HTTP/2 meet there. No cast is needed in the test, The handler fits each listener best. Then hops away to nibble a leaf.
Recent review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 542bccc1-7dcf-44cf-89f0-4d856649111c
Commits
Reviewing files that changed from the base of the PR and between a84f62b and 50b7d41.
Files selected for processing: 5
src/adapters/_node/adapter.ts
test/node-adapters.test.ts
test/node-error-paths.test.ts
test/node-promises.test.ts
test/types.test-d.ts
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
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
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.
resolves #367
toNodeHandler()returnedNodeHttpHandler & AdapterMeta, a union of the http1 and http2 handler types, which is not assignable to the request listener ofnode:http,node:httpsornode:http2. The function it returns takesNodeServerRequest/NodeServerResponseand handles both protocols, so the return type is nowNodeHttp1Handler & NodeHttp2Handler & AdapterMeta.This is a type-only change:
toFetchHandler()round trip returns the original__nodeHandler, which is typed as the union, so that branch has one cast. The intersection is optimistic there if the original handler was written for a single protocol.as NodeHttp1Handlercasts ontoNodeHandler()results in the tests are removed.test/types.test-d.tsasserts the result extends both request listener types.Verification
tsc --strictcheck passing the result tohttp.createServer,https.createServer,http2.createServerandhttp2.createSecureServerpasses with this change and reports 6 errors without it.pnpm lint,pnpm typecheckand the vitest suite. Relying on CI for those.Summary by CodeRabbit
toNodeHandleris now typed for use with both HTTP/1 and HTTP/2 servers, includingnode:http,node:https, andnode:http2.