Skip to content

Commit 3f0b5ea

Browse files
committed
Update GenericRequiestHandler signature
1 parent a7bcba8 commit 3f0b5ea

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

packages/remix/src/utils/serverAdapters/shared.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ async function finishSentryProcessing(res: AugmentedResponse): Promise<void> {
114114

115115
function startRequestHandlerTransactionWithRoutes(
116116
this: unknown,
117-
handler: GenericRequestHandler<SupportedResponse>,
117+
handler: GenericRequestHandler,
118118
framework: SupportedFramework,
119119
routes: ServerRoute[],
120120
req: SupportedRequest,
@@ -144,13 +144,13 @@ function startRequestHandlerTransactionWithRoutes(
144144
}
145145

146146
export const wrapRequestHandler = <NextFn>(
147-
handler: GenericRequestHandler<SupportedResponse>,
147+
handler: GenericRequestHandler,
148148
framework: SupportedFramework,
149149
readyBuildOrGetBuildFn: ServerBuild | (() => Promise<ServerBuild> | ServerBuild),
150-
): GenericRequestHandler<SupportedResponse> => {
150+
): GenericRequestHandler => {
151151
let routes: ServerRoute[];
152152

153-
return async function (this: unknown, req: PolymorphicRequest, res: SupportedResponse, next: NextFn): Promise<SupportedResponse | null> {
153+
return async function (this: unknown, req: PolymorphicRequest, res: SupportedResponse, next: NextFn): Promise<FastifyReply | null> {
154154
const isExpress = framework === SupportedFramework.Express;
155155
const isFastify = framework === SupportedFramework.Fastify;
156156
await withIsolationScope(async isolationScope => {
@@ -191,19 +191,19 @@ export const wrapRequestHandler = <NextFn>(
191191
// Fastify wants us to _return_ the "reply" instance
192192
// in case we are sending a response ourselves, which
193193
// we _are_ doing by means of`reply.send(data)`.
194-
return isFastify ? res : null;
194+
return isFastify ? res as FastifyReply : null;
195195
};
196196
};
197197

198198
export const prepareWrapCreateRequestHandler = (forFramework: SupportedFramework) =>
199199
function wrapCreateRequestHandler(
200-
createRequestHandler: CreateGenericRequestHandler<SupportedResponse>,
201-
): (this: unknown, options: CreateRequestHandlerOptions) => GenericRequestHandler<SupportedResponse> {
202-
return function (this: unknown, opts: CreateRequestHandlerOptions): GenericRequestHandler<SupportedResponse> {
203-
if (!opts.getLoadContext) opts['getLoadContext'] = () => ({});
200+
createRequestHandler: CreateGenericRequestHandler,
201+
): (this: unknown, options: CreateRequestHandlerOptions) => GenericRequestHandler {
202+
return function (this: unknown, opts: CreateRequestHandlerOptions): GenericRequestHandler {
203+
if (!('getLoadContext' in opts)) opts['getLoadContext'] = () => ({});
204204
fill(opts, 'getLoadContext', wrapGetLoadContext(forFramework));
205205
const build = typeof opts.build === 'function' ? wrapBuildFn(opts.build) : instrumentBuild(opts.build, true);
206-
const handler: GenericRequestHandler<SupportedResponse> = createRequestHandler.call(this, { ...opts, build });
206+
const handler: GenericRequestHandler= createRequestHandler.call(this, { ...opts, build });
207207
return wrapRequestHandler(handler, forFramework, build);
208208
};
209209
};

packages/remix/src/utils/vendor/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,9 @@ export interface AssetsManifest {
237237
version: string;
238238
}
239239

240-
export type GenericRequestHandler<R> = (req: any, res: R, next: any) => Promise<R | null>;
240+
export type GenericRequestHandler = (req: any, res: any, next: any) => Promise<any>;
241241

242-
export type CreateGenericRequestHandler<R> = (this: unknown, options: any) => GenericRequestHandler<R>;
242+
export type CreateGenericRequestHandler = (this: unknown, options: any) => GenericRequestHandler;
243243

244244
export interface CreateRequestHandlerOptions {
245245
build: ServerBuild | (() => ServerBuild) | (() => Promise<ServerBuild>);

0 commit comments

Comments
 (0)