11import { customErrorTypes } from "~/types/error" ;
22import type { HttpMethod } from "~/types/http" ;
33import type { RouteHandler , RouteMethodHandler } from "~/types/next" ;
4+ import type { FixPathParams } from "~/types/path-params" ;
45import type { ResponseCollection } from "~/types/response" ;
56import { parseRequestBody , resolveRequestBody } from "./body" ;
67import { resolveParams } from "./params" ;
@@ -62,8 +63,8 @@ type RouteOptions<
6263 issues ?: ZodIssue [ ] ,
6364 ) => Res ,
6465 middleware ?: (
65- hander : RouteMethodHandler < PathParamsInput , Req , Res > ,
66- ) => RouteMethodHandler < PathParamsInput , Req , Res > ,
66+ hander : RouteMethodHandler < FixPathParams < PathParamsInput > , Req , Res > ,
67+ ) => RouteMethodHandler < FixPathParams < PathParamsInput > , Req , Res > ,
6768 security ?: OperationObject [ "security" ] ,
6869} & ( RouteWithBody < RequestBodyInput , RequestBodyOutput > | RouteWithoutBody ) ;
6970
@@ -80,12 +81,12 @@ function defineRoute<
8081 ResDef extends Record < string , unknown > ,
8182> ( input : RouteOptions <
8283 M , PPI , PPO , QPI , QPO , RBI , RBO , MwReq , MwRes , ResDef
83- > ) {
84- const handler : RouteMethodHandler < PPI , MwReq , MwRes > = async ( request , context ) => {
84+ > ) : RouteHandler < M , FixPathParams < PPI > , MwReq , MwRes > {
85+ const handler : RouteMethodHandler < FixPathParams < PPI > , MwReq , MwRes > = async ( request , context ) => {
8586 try {
8687 const { searchParams } = new URL ( request . url ) ;
8788 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
88- const nextSegmentParams = context ? ( await context . params ) : undefined ;
89+ const nextSegmentParams = context ? ( await context . params ) as PPI : undefined ;
8990 const pathParams = parsePathParams ( nextSegmentParams , input . pathParams ) as PPO ;
9091 const queryParams = parseSearchParams ( searchParams , input . queryParams ) as QPO ;
9192 const body = await parseRequestBody ( request , input . method , input . requestBody , input . hasFormData ) as RBO ;
@@ -154,10 +155,10 @@ function defineRoute<
154155 if ( input . middleware ) {
155156 const alteredHandler = input . middleware ( handler ) ;
156157 alteredHandler . apiData = handler . apiData ;
157- return { [ input . method ] : alteredHandler } as RouteHandler < M , PPI , MwReq , MwRes > ;
158+ return { [ input . method ] : alteredHandler } as RouteHandler < M , FixPathParams < PPI > , MwReq , MwRes > ;
158159 }
159160
160- return { [ input . method ] : handler } as RouteHandler < M , PPI , MwReq , MwRes > ;
161+ return { [ input . method ] : handler } as RouteHandler < M , FixPathParams < PPI > , MwReq , MwRes > ;
161162}
162163
163164export default defineRoute ;
0 commit comments