@@ -12,7 +12,7 @@ import type {
1212 useLazyAsyncData ,
1313 useLazyFetch ,
1414} from 'nuxt/app' ;
15- import type { MaybeRefOrGetter } from 'vue' ;
15+ import type { MaybeRef , MaybeRefOrGetter } from 'vue' ;
1616
1717export type ArraySeparatorStyle = ArrayStyle | MatrixStyle ;
1818type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited' ;
@@ -24,6 +24,11 @@ export type QuerySerializer = (
2424 query : Parameters < Client [ 'buildUrl' ] > [ 0 ] [ 'query' ] ,
2525) => string ;
2626
27+ export type FetchHeaders =
28+ | HeadersInit
29+ | MaybeRef < HeadersInit >
30+ | Record < string , unknown > ;
31+
2732/**
2833 * KeysOf, copied from Nuxt, is used depending on the composable to "pick" the keys
2934 * on the return type, so only a sub-set of the data is returned via hydration,
@@ -43,7 +48,7 @@ export interface Config<T extends ClientOptions = ClientOptions>
4348 * Base URL for all requests made by this client.
4449 */
4550 baseURL ?: T [ 'baseURL' ] ;
46- headers ?: FetchOptions [ 'headers' ] ;
51+ headers ?: FetchHeaders ;
4752 /**
4853 * A function for serializing request query parameters. By default, arrays
4954 * will be exploded in form style, objects will be exploded in deepObject
@@ -60,15 +65,14 @@ export interface RequestOptions<
6065 DefaultT = undefined ,
6166 Url extends string = string ,
6267> extends Config ,
63- Pick < RefTDataShape < TDataShape > , 'body' | 'path' | 'query' > {
68+ Pick < RefTDataShape < TDataShape > , 'body' | 'path' | 'query' | 'headers' > {
6469 asyncDataOptions ?: AsyncDataOptions < ResT , ResT , KeysOf < ResT > , DefaultT > ;
6570 /**
6671 * Any body that you want to add to your request.
6772 *
6873 * {@link https://developer.mozilla.org/docs/Web/API/fetch#body}
6974 */
7075 composable : TComposable ;
71- headers ?: FetchOptions [ 'headers' ] ;
7276 key ?: string ;
7377 /**
7478 * Security mechanism(s) to use for the request.
@@ -110,12 +114,7 @@ type MethodFn = <
110114 TError = unknown ,
111115 DefaultT = undefined ,
112116> (
113- options : Omit <
114- RequestOptions < TComposable , ResT , DefaultT > ,
115- 'method' | 'headers'
116- > & {
117- headers ?: FetchOptions [ 'headers' ] ;
118- } ,
117+ options : Omit < RequestOptions < TComposable , ResT , DefaultT > , 'method' > ,
119118) => RequestResult < TComposable , ResT , TError > ;
120119
121120type RequestFn = <
@@ -142,7 +141,7 @@ export type CreateClientConfig<T extends ClientOptions = ClientOptions> = (
142141
143142export interface TDataShape {
144143 body ?: FetchOptions [ 'body' ] ;
145- headers ?: unknown ;
144+ headers ?: FetchHeaders ;
146145 path ?: FetchOptions [ 'query' ] ;
147146 query ?: FetchOptions [ 'query' ] ;
148147 url : string ;
@@ -182,11 +181,9 @@ export type Options<
182181 DefaultT = undefined ,
183182> = Omit <
184183 RequestOptions < TComposable , ResT , DefaultT > ,
185- 'body' | 'url' | 'query' | 'path'
184+ 'body' | 'url' | 'query' | 'path' | 'headers'
186185> &
187- Pick < RefTDataShape < TData > , 'body' | 'query' | 'path' > & {
188- headers ?: FetchOptions [ 'headers' ] ;
189- } ;
186+ Pick < RefTDataShape < TData > , 'body' | 'query' | 'path' | 'headers' > ;
190187
191188export type OptionsLegacyParser < TData = unknown > = TData extends { body ?: any }
192189 ? TData extends { headers ?: any }
0 commit comments