@@ -183,6 +183,7 @@ function wrapMiddlewares(middlewares: Middleware[], fetch: Fetch): Fetch {
183183 return fetch ( url , init )
184184 }
185185 const current = middlewares [ index ]
186+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
186187 return await current ! ( url , init , ( nextUrl , nextInit ) =>
187188 handler ( index + 1 , nextUrl , nextInit ) ,
188189 )
@@ -228,7 +229,7 @@ function createFetch<OP>(fetch: _TypedFetch<OP>): TypedFetch<OP> {
228229}
229230
230231function fetcher < Paths > ( ) {
231- let baseUrl = ''
232+ let baseUrl = '' as string | ( ( ) => string )
232233 let defaultInit : RequestInit = { }
233234 const middlewares : Middleware [ ] = [ ]
234235 const fetch = wrapMiddlewares ( middlewares , fetchJson )
@@ -246,15 +247,17 @@ function fetcher<Paths>() {
246247 create : ( ( queryParams ?: Record < string , true | 1 > ) =>
247248 createFetch ( ( payload , init ) =>
248249 fetchUrl ( {
249- baseUrl : baseUrl || '' ,
250+ baseUrl :
251+ init ?. baseUrl ??
252+ ( typeof baseUrl === 'function' ? baseUrl ( ) : baseUrl ) ,
250253 path : path as string ,
251254 method : method as Method ,
252255 queryParams : Object . keys ( queryParams || { } ) ,
253256 payload,
254257 init : mergeRequestInit ( defaultInit , init ) ,
255258 fetch,
256259 } ) ,
257- ) ) as CreateFetch < M , Paths [ P ] [ M ] > ,
260+ ) ) as unknown as CreateFetch < M , Paths [ P ] [ M ] > ,
258261 } ) ,
259262 } ) ,
260263 }
0 commit comments