Skip to content

fix(types): correct onResponse hook response parameter type - #495

Open
koding88 wants to merge 1 commit into
fastify:mainfrom
koding88:fix/on-response-hook-types
Open

fix(types): correct onResponse hook response parameter type#495
koding88 wants to merge 1 commit into
fastify:mainfrom
koding88:fix/on-response-hook-types

Conversation

@koding88

Copy link
Copy Markdown

Fixes #494

The onResponse hook previously typed its third argument (res) as an outgoing ServerResponse via RawReplyDefaultExpression. At runtime, the third argument is a plain object representing the upstream incoming response payload ({ statusCode, headers, stream }).

  • Defined FastifyReplyFromResponse with statusCode, headers, and stream: Readable (matching all transports: http, undici, http2).
  • Updated onResponse parameter type to FastifyReplyFromResponse.
  • Preserved RawServerResponse export for backwards compatibility.
  • Added type assertions in types/index.tst.ts.

Copilot AI lite review requested due to automatic review settings August 28, 2026 03:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR corrects the TypeScript types for the onResponse hook in @fastify/reply-from so the third parameter reflects the actual runtime shape ({ statusCode, headers, stream }) rather than an outgoing ServerResponse.

Changes:

  • Introduces FastifyReplyFromResponse (statusCode, headers, stream: Readable) to represent the upstream response object.
  • Updates onResponse hook typing to use FastifyReplyFromResponse while keeping the existing RawServerResponse export.
  • Updates type assertions in types/index.tst.ts to validate the new onResponse parameter shape.

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 1 comment.

File Description
types/index.d.ts Adds FastifyReplyFromResponse and updates onResponse to use it.
types/index.tst.ts Adjusts type assertions to validate the new onResponse response parameter shape.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread types/index.tst.ts
Comment on lines +88 to 92
expect(res).type.toBe<FastifyReplyFromResponse>()
expect(res.statusCode).type.toBe<number>()
expect(res.headers).type.toBe<Http1IncomingHttpHeaders | IncomingHttpHeaders>()
expect(res.stream).type.toBe<Readable>()
}
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.

onResponse hook types its response argument as an outgoing ServerResponse, but receives { statusCode, headers, stream }

2 participants