55 MicroCMSQueries ,
66} from 'microcms-js-sdk' ;
77import { useFetch , useRuntimeConfig } from 'nuxt/app' ;
8- import type { FetchOptions as _FetchOptions } from 'ofetch' ;
8+ import type { FetchError } from 'ofetch' ;
99import { computed } from 'vue' ;
1010
1111import { useMicroCMSUrl } from './useMicroCMSUrl' ;
@@ -31,13 +31,16 @@ type MicroCMSGetObjectArgs = {
3131 queries ?: MicroCMSQueries ;
3232} ;
3333
34- type FetchOptions = Omit < _FetchOptions < 'json' > , 'baseURL' | 'query' | 'method' > ;
34+ type FetchOptions < T extends unknown > = Omit <
35+ Parameters < typeof useFetch < T , FetchError , string , 'get' > > ,
36+ 'baseURL' | 'query' | 'method'
37+ > [ 1 ] ;
3538
3639const method = 'GET' ;
3740
3841const useMicroCMSGet = < T > (
3942 { url, queries } : MicroCMSGetArgs ,
40- fetchOptions : FetchOptions = { }
43+ fetchOptions : FetchOptions < T > = { }
4144) => {
4245 const baseURL = useMicroCMSUrl ( ) ;
4346 const config = useRuntimeConfig ( ) ;
@@ -52,12 +55,14 @@ const useMicroCMSGet = <T>(
5255 : undefined
5356 ) ;
5457
55- return useFetch < T > ( url , {
58+ return useFetch < T , FetchError , string , 'get' > ( url , {
5659 ...fetchOptions ,
5760 baseURL,
5861 query,
5962 headers : {
60- 'X-MICROCMS-API-KEY' : config . microCMS ?. apiKey ,
63+ 'X-MICROCMS-API-KEY' : config . microCMS
64+ ? config . microCMS . apiKey
65+ : config . public . microCMS . apiKey ,
6166 ...fetchOptions . headers ,
6267 } ,
6368 method,
@@ -66,7 +71,7 @@ const useMicroCMSGet = <T>(
6671
6772export const useMicroCMSGetList = < T > (
6873 { endpoint, queries } : MicroCMSGetListArgs ,
69- fetchOptions : FetchOptions = { }
74+ fetchOptions : FetchOptions < MicroCMSListResponse < T > > = { }
7075) => {
7176 return useMicroCMSGet < MicroCMSListResponse < T > > (
7277 { url : endpoint , queries } ,
@@ -76,7 +81,7 @@ export const useMicroCMSGetList = <T>(
7681
7782export const useMicroCMSGetListDetail = < T > (
7883 { endpoint, contentId, queries } : MicroCMSGetListDetailArgs ,
79- fetchOptions : FetchOptions = { }
84+ fetchOptions : FetchOptions < T & MicroCMSListContent > = { }
8085) => {
8186 return useMicroCMSGet < T & MicroCMSListContent > (
8287 { url : `${ endpoint } /${ contentId } ` , queries } ,
@@ -86,7 +91,7 @@ export const useMicroCMSGetListDetail = <T>(
8691
8792export const useMicroCMSGetObject = < T > (
8893 { endpoint, queries } : MicroCMSGetObjectArgs ,
89- fetchOptions : FetchOptions = { }
94+ fetchOptions : FetchOptions < T & MicroCMSObjectContent > = { }
9095) => {
9196 return useMicroCMSGet < T & MicroCMSObjectContent > (
9297 { url : endpoint , queries } ,
0 commit comments