Skip to content

Commit

Permalink
fix: explicitly declare return type of useSanityQuery
Browse files Browse the repository at this point in the history
resolves #915
  • Loading branch information
danielroe committed Nov 16, 2023
1 parent 9c2673b commit 5cb1833
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/runtime/composables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { defu } from 'defu'
import { hash } from 'ohash'
import { reactive } from 'vue'

import type { AsyncDataOptions } from 'nuxt/app'
import type { AsyncData, AsyncDataOptions } from 'nuxt/app'
import type { SanityClient, SanityConfiguration } from './client'
import { useNuxtApp, useRuntimeConfig, useAsyncData, useLazyAsyncData, createSanityClient } from '#imports'

Expand Down Expand Up @@ -56,24 +56,24 @@ interface UseSanityQueryOptions<T> extends AsyncDataOptions<T> {
client?: string
}

export const useSanityQuery = <T = unknown, E = Error> (query: string, _params?: Record<string, any>, _options: UseSanityQueryOptions<T> = {}) => {
export const useSanityQuery = <T = unknown, E = Error> (query: string, _params?: Record<string, any>, _options: UseSanityQueryOptions<T> = {}): AsyncData<T | null, E> => {
const { client, ...options } = _options
const sanity = useSanity(client)
const params = _params ? reactive(_params) : undefined
if (params) {
options.watch = options.watch || []
options.watch.push(params)
}
return useAsyncData<T, E>('sanity-' + hash(query + (params ? JSON.stringify(params) : '')), () => sanity.fetch<T>(query, params), options)
return useAsyncData('sanity-' + hash(query + (params ? JSON.stringify(params) : '')), () => sanity.fetch<T>(query, params), options) as AsyncData<T | null, E>
}

export const useLazySanityQuery = <T = unknown, E = Error> (query: string, _params?: Record<string, any>, _options: UseSanityQueryOptions<T> = {}) => {
export const useLazySanityQuery = <T = unknown, E = Error> (query: string, _params?: Record<string, any>, _options: UseSanityQueryOptions<T> = {}): AsyncData<T | null, E> => {
const { client, ...options } = _options
const sanity = useSanity(client)
const params = _params ? reactive(_params) : undefined
if (params) {
options.watch = options.watch || []
options.watch.push(params)
}
return useLazyAsyncData<T, E>('sanity-' + hash(query + (params ? JSON.stringify(params) : '')), () => sanity.fetch<T>(query, params), options)
return useLazyAsyncData('sanity-' + hash(query + (params ? JSON.stringify(params) : '')), () => sanity.fetch<T>(query, params), options) as AsyncData<T | null, E>
}

0 comments on commit 5cb1833

Please sign in to comment.