diff --git a/packages/remix/src/server/instrumentServer.ts b/packages/remix/src/server/instrumentServer.ts index 3417188cc7d5..4f67f2ae8b3d 100644 --- a/packages/remix/src/server/instrumentServer.ts +++ b/packages/remix/src/server/instrumentServer.ts @@ -246,12 +246,9 @@ function makeWrappedRootLoader() { }; } -function wrapRequestHandler( +function wrapRequestHandler ServerBuild | Promise)>( origRequestHandler: RequestHandler, - build: - | ServerBuild - | { build: ServerBuild } - | (() => ServerBuild | { build: ServerBuild } | Promise), + build: T, options?: { instrumentTracing?: boolean; }, @@ -278,7 +275,7 @@ function wrapRequestHandler( // check if the build is nested under `build` key if ('build' in resolvedBuild) { - resolvedRoutes = createRoutes(resolvedBuild.build.routes); + resolvedRoutes = createRoutes((resolvedBuild.build as ServerBuild).routes); } else { resolvedRoutes = createRoutes(resolvedBuild.routes); } @@ -407,12 +404,12 @@ function instrumentBuildCallback( /** * Instruments `remix` ServerBuild for performance tracing and error tracking. */ -export function instrumentBuild( - build: ServerBuild | (() => ServerBuild | Promise), +export function instrumentBuild ServerBuild | Promise)>( + build: T, options?: { instrumentTracing?: boolean; }, -): ServerBuild | (() => ServerBuild | Promise) { +): T { if (typeof build === 'function') { return function () { const resolvedBuild = build(); @@ -424,19 +421,15 @@ export function instrumentBuild( } else { return instrumentBuildCallback(resolvedBuild, options); } - }; + } as T; } else { - return instrumentBuildCallback(build, options); + return instrumentBuildCallback(build, options) as T; } } export const makeWrappedCreateRequestHandler = (options?: { instrumentTracing?: boolean }) => function (origCreateRequestHandler: CreateRequestHandlerFunction): CreateRequestHandlerFunction { - return function ( - this: unknown, - build: ServerBuild | (() => ServerBuild | Promise), - ...args: unknown[] - ): RequestHandler { + return function (this: unknown, build, ...args: unknown[]): RequestHandler { const newBuild = instrumentBuild(build, options); const requestHandler = origCreateRequestHandler.call(this, newBuild, ...args);