@@ -246,12 +246,9 @@ function makeWrappedRootLoader() {
246
246
} ;
247
247
}
248
248
249
- function wrapRequestHandler (
249
+ function wrapRequestHandler < T extends ServerBuild | ( ( ) => ServerBuild | Promise < ServerBuild > ) > (
250
250
origRequestHandler : RequestHandler ,
251
- build :
252
- | ServerBuild
253
- | { build : ServerBuild }
254
- | ( ( ) => ServerBuild | { build : ServerBuild } | Promise < ServerBuild | { build : ServerBuild } > ) ,
251
+ build : T ,
255
252
options ?: {
256
253
instrumentTracing ?: boolean ;
257
254
} ,
@@ -278,7 +275,7 @@ function wrapRequestHandler(
278
275
279
276
// check if the build is nested under `build` key
280
277
if ( 'build' in resolvedBuild ) {
281
- resolvedRoutes = createRoutes ( resolvedBuild . build . routes ) ;
278
+ resolvedRoutes = createRoutes ( ( resolvedBuild . build as ServerBuild ) . routes ) ;
282
279
} else {
283
280
resolvedRoutes = createRoutes ( resolvedBuild . routes ) ;
284
281
}
@@ -407,12 +404,12 @@ function instrumentBuildCallback(
407
404
/**
408
405
* Instruments `remix` ServerBuild for performance tracing and error tracking.
409
406
*/
410
- export function instrumentBuild (
411
- build : ServerBuild | ( ( ) => ServerBuild | Promise < ServerBuild > ) ,
407
+ export function instrumentBuild < T extends ServerBuild | ( ( ) => ServerBuild | Promise < ServerBuild > ) > (
408
+ build : T ,
412
409
options ?: {
413
410
instrumentTracing ?: boolean ;
414
411
} ,
415
- ) : ServerBuild | ( ( ) => ServerBuild | Promise < ServerBuild > ) {
412
+ ) : T {
416
413
if ( typeof build === 'function' ) {
417
414
return function ( ) {
418
415
const resolvedBuild = build ( ) ;
@@ -424,19 +421,15 @@ export function instrumentBuild(
424
421
} else {
425
422
return instrumentBuildCallback ( resolvedBuild , options ) ;
426
423
}
427
- } ;
424
+ } as T ;
428
425
} else {
429
- return instrumentBuildCallback ( build , options ) ;
426
+ return instrumentBuildCallback ( build , options ) as T ;
430
427
}
431
428
}
432
429
433
430
export const makeWrappedCreateRequestHandler = ( options ?: { instrumentTracing ?: boolean } ) =>
434
431
function ( origCreateRequestHandler : CreateRequestHandlerFunction ) : CreateRequestHandlerFunction {
435
- return function (
436
- this : unknown ,
437
- build : ServerBuild | ( ( ) => ServerBuild | Promise < ServerBuild > ) ,
438
- ...args : unknown [ ]
439
- ) : RequestHandler {
432
+ return function ( this : unknown , build , ...args : unknown [ ] ) : RequestHandler {
440
433
const newBuild = instrumentBuild ( build , options ) ;
441
434
const requestHandler = origCreateRequestHandler . call ( this , newBuild , ...args ) ;
442
435
0 commit comments