11import type { NextRequest } from 'next/server'
2- import type { Context } from '../../types '
2+ import type { Context } from '../../context '
33import type { FetchHandleOptions , FetchHandler } from '../fetch'
44import { value , type Value } from '@orpc/shared'
55
66export type ServeOptions < T extends Context > =
77 & Omit < FetchHandleOptions < T > , 'context' >
8- & ( undefined extends T ? { context ?: Value < T , [ NextRequest ] > } : { context : Value < T , [ NextRequest ] > } )
8+ & ( Record < never , never > extends T ? { context ?: Value < T , [ NextRequest ] > } : { context : Value < T , [ NextRequest ] > } )
99
10- export type ServeRest < T extends Context > = [ options : ServeOptions < T > ] | ( undefined extends T ? [ ] : never )
10+ export type ServeRest < T extends Context > =
11+ | [ options : ServeOptions < T > ]
12+ | ( Record < never , never > extends T ? [ ] : never )
1113
1214export interface ServeResult {
1315 GET : ( req : NextRequest ) => Promise < Response >
@@ -19,7 +21,7 @@ export interface ServeResult {
1921
2022export function serve < T extends Context > ( handler : FetchHandler < T > , ...[ options ] : ServeRest < T > ) : ServeResult {
2123 const main = async ( req : NextRequest ) => {
22- const context = await value ( options ?. context , req ) as any
24+ const context = await value ( options ?. context ?? { } , req ) as any
2325
2426 const { matched, response } = await handler . handle ( req , { ...options , context } )
2527
0 commit comments