nuxt / nuxt

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

`useFetch` and `useAsyncData` type inference incorrect for generic parameter #28030

Open miosenpai opened 4 months ago

miosenpai commented 4 months ago

Environment

------------------------------
- Operating System: Linux
- Node Version:     v18.20.3
- Nuxt Version:     3.12.3
- CLI Version:      3.12.0
- Nitro Version:    2.9.7
- Package Manager:  npm@10.2.3
- Builder:          -
- User Config:      devtools
- Runtime Modules:  -
- Build Modules:    -
------------------------------

Reproduction

https://stackblitz.com/edit/github-8k6key?file=composables%2FuseCustomData.ts

Describe the bug

When you use a generic parameter (e.g. the T in <T>(...)) to type the returned data of useFetch or useAsyncData, the functions end up inferring the returned data's type to be something with no fields in it (even if T was guaranteed to have certain fields via extends).

Other functions don't seem to have this problem (e.g. $fetch as demonstrated in the reproduction), so this behavior is unlikely to be caused by TypeScript itself (I think it might have something to do with how the pick option affects the type inference process).

Additional context

No response

Logs

No response

stackblitz[bot] commented 4 months ago

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