nuxt / nuxt

The Intuitive Vue Framework.
https://nuxt.com
MIT License
54.98k stars 5.03k forks source link

Custom `useFetch` has incorrect type for `default` option #29970

Open TheColorman opened 5 hours ago

TheColorman commented 5 hours ago

Environment

Working directory: /home/projects/nuxt-starter-r4dshc Nuxt project info:


Reproduction

https://stackblitz.com/edit/nuxt-starter-r4dshc?file=composables%2Ftest.ts&view=editor

The issue is in the composables/test.ts file, and appears as an error on the default property.

Describe the bug

When creating a custom wrapper for useFetch as described in the documentation, the default option of UseFetchOptions is always () => Ref<null, null> | null, no matter what the type passed to UseFetchOptions is.

Additional context

As far as I can tell from looking through the type definitions, only the main ResT type is passed to the UseFetchOptions type: Image

The type used for the default option function comes from DefaultT on UseFetchOptions: Image Image

When using useFetch normally, DefaultT is set to the same type as ResT, but when using the custom wapper, DefaultT instead uses its default type of DefaultAsyncDataValue, which is null.

This is solvable by copying the types defined by useFetch and passed to UseFetchOptions, but this is not a realistic option because it requires a significant amount of boilerplate typing for the wrapper function.

Logs

stackblitz[bot] commented 5 hours ago

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.