Skip to content

Commit 54dc541

Browse files
committed
Fix signature of Fastify Reply in FastifyAdapter
v5 added a generic which Nest has not yet upgraded too.
1 parent 0c33b83 commit 54dc541

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

src/core/http/http.adapter.ts

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,18 @@ import {
1212
FastifyAdapter,
1313
NestFastifyApplication,
1414
} from '@nestjs/platform-fastify';
15-
import type { FastifyInstance, HTTPMethods, RouteOptions } from 'fastify';
15+
import type {
16+
FastifyInstance,
17+
FastifyReply,
18+
FastifyRequest,
19+
HTTPMethods,
20+
RawReplyDefaultExpression,
21+
RawRequestDefaultExpression,
22+
RawServerBase,
23+
RawServerDefault,
24+
RequestGenericInterface,
25+
RouteOptions,
26+
} from 'fastify';
1627
import rawBody from 'fastify-raw-body';
1728
import * as zlib from 'node:zlib';
1829
import { uniqueDiscoveredMethods } from '~/common/discovery-unique-methods';
@@ -34,8 +45,41 @@ export type NestHttpApplication = NestFastifyApplication & {
3445

3546
export class HttpAdapterHost extends HttpAdapterHostImpl<HttpAdapter> {}
3647

48+
type FastifyRawRequest<TServer extends RawServerBase> =
49+
RawRequestDefaultExpression<TServer> & {
50+
originalUrl?: string;
51+
};
52+
3753
// @ts-expect-error Convert private methods to protected
38-
class PatchedFastifyAdapter extends FastifyAdapter {
54+
class PatchedFastifyAdapter<
55+
TServer extends RawServerBase = RawServerDefault,
56+
TRawRequest extends FastifyRawRequest<TServer> = FastifyRawRequest<TServer>,
57+
TRawResponse extends RawReplyDefaultExpression<TServer> = RawReplyDefaultExpression<TServer>,
58+
TRequest extends FastifyRequest<
59+
RequestGenericInterface,
60+
TServer,
61+
TRawRequest
62+
> = FastifyRequest<RequestGenericInterface, TServer, TRawRequest>,
63+
TReply extends FastifyReply<
64+
RequestGenericInterface,
65+
TServer,
66+
TRawRequest,
67+
TRawResponse
68+
> = FastifyReply<RequestGenericInterface, TServer, TRawRequest, TRawResponse>,
69+
TInstance extends FastifyInstance<
70+
TServer,
71+
TRawRequest,
72+
TRawResponse
73+
> = FastifyInstance<TServer, TRawRequest, TRawResponse>,
74+
> extends FastifyAdapter<
75+
TServer,
76+
TRawRequest,
77+
TRawResponse,
78+
TRequest,
79+
// @ts-expect-error they haven't upgraded to v5 signature yet.
80+
TReply,
81+
TInstance
82+
> {
3983
protected injectRouteOptions(
4084
routerMethodKey: Uppercase<HTTPMethods>,
4185
...args: any[]

0 commit comments

Comments
 (0)