Closed kingyue737 closed 5 months ago
Seems reasonable to send a PR ;)
Here is a workaround!
function useAPI<T>(
url: string | (() => string),
options: Omit<UseFetchOptions<T>, 'default'> & { default: () => T | Ref<T> },
) {
return useFetch(url, {
...options,
})
}
const { data: data2 } = useAPI<{ bug: string }[]>('/', {
default: () => [],
})
data2.value.push({ bug: 'bug' })
The useFetch
returns data null if the default
option is undefined, so the error can be resolved by making default
required in the options of the useAPI
.
Updated in the article thank you!
Reproduction: https://stackblitz.com/edit/atinotes-1
Thanks for sharing the way to make a custom
useFetch
. But I found some type bugs withuseAPI
:useAPI
still returns a nullable data:Original
useFetch
has no such issue.