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..c77db3ac 100644 --- a/types/index.tst.ts +++ b/types/index.tst.ts @@ -12,8 +12,11 @@ import * as https from 'node:https' import { Agent, Client, Dispatcher, Pool } from 'undici' import replyFrom, { type FastifyReplyFromOptions, + type FastifyReplyFromResponse, type RawServerResponse } from '.' +import { type IncomingHttpHeaders as Http1IncomingHttpHeaders } from 'node:http' +import { type Readable } from 'node:stream' const fullOptions: FastifyReplyFromOptions = { base: 'http://example2.com', @@ -83,8 +86,11 @@ 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() + expect>().type.toBe>() } }) })