From 238c8657ac358791783ba35458681bad7c6de472 Mon Sep 17 00:00:00 2001 From: koding88 Date: Fri, 28 Aug 2026 10:18:27 +0700 Subject: [PATCH 1/2] fix(types): correct onResponse hook response parameter type (#494) --- types/index.d.ts | 9 ++++++++- types/index.tst.ts | 8 ++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index 6a8fb272..cc8d002b 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -18,6 +18,7 @@ import { IncomingMessage, RequestOptions, } from 'node:http' +import { Readable } from 'node:stream' import { ClientSessionOptions, ClientSessionRequestOptions, @@ -66,6 +67,12 @@ declare namespace fastifyReplyFrom { stream: IncomingMessage } + export interface FastifyReplyFromResponse { + statusCode: number + headers: IncomingHttpHeaders | Http2IncomingHttpHeaders + stream: Readable + } + export interface FastifyReplyFromHooks { queryString?: { [key: string]: unknown } | QueryStringFunction; contentType?: string; @@ -74,7 +81,7 @@ declare namespace fastifyReplyFrom { onResponse?: ( request: FastifyRequest, reply: FastifyReply, - res: RawServerResponse + res: FastifyReplyFromResponse ) => void; onError?: ( reply: FastifyReply, diff --git a/types/index.tst.ts b/types/index.tst.ts index 5e2bf6f8..c8c5c50f 100644 --- a/types/index.tst.ts +++ b/types/index.tst.ts @@ -12,8 +12,10 @@ import * as https from 'node:https' import { Agent, Client, Dispatcher, Pool } from 'undici' import replyFrom, { type FastifyReplyFromOptions, - type RawServerResponse + type FastifyReplyFromResponse } from '.' +import { type IncomingHttpHeaders as Http1IncomingHttpHeaders } from 'node:http' +import { type Readable } from 'node:stream' const fullOptions: FastifyReplyFromOptions = { base: 'http://example2.com', @@ -83,8 +85,10 @@ app.get('/v3', (_request, reply) => { onResponse (request, reply, res) { expect(request).type.toBe>() expect(reply).type.toBe>() - expect(res).type.toBe>() + expect(res).type.toBe() expect(res.statusCode).type.toBe() + expect(res.headers).type.toBe() + expect(res.stream).type.toBe() } }) }) From 23e5eacd5d1f29752e47a3e4d330d6abda9538b5 Mon Sep 17 00:00:00 2001 From: Tony133 Date: Fri, 23 Oct 2026 10:09:54 +0200 Subject: [PATCH 2/2] test: assert RawServerResponse is still exported --- types/index.tst.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/types/index.tst.ts b/types/index.tst.ts index c8c5c50f..c77db3ac 100644 --- a/types/index.tst.ts +++ b/types/index.tst.ts @@ -12,7 +12,8 @@ import * as https from 'node:https' import { Agent, Client, Dispatcher, Pool } from 'undici' import replyFrom, { type FastifyReplyFromOptions, - type FastifyReplyFromResponse + type FastifyReplyFromResponse, + type RawServerResponse } from '.' import { type IncomingHttpHeaders as Http1IncomingHttpHeaders } from 'node:http' import { type Readable } from 'node:stream' @@ -89,6 +90,7 @@ app.get('/v3', (_request, reply) => { expect(res.statusCode).type.toBe() expect(res.headers).type.toBe() expect(res.stream).type.toBe() + expect>().type.toBe>() } }) })