-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
useFetch Serialize Type #27968
Description
Environment
- Operating System: Windows_NT
- Node Version: v20.9.0
- Nuxt Version: 3.12.1
- CLI Version: 3.12.0
- Nitro Version: 2.9.6
- Package Manager: npm@10.1.0
- Builder: -
- User Config: css, build, nitro, vite, telemetry, modules, runtimeConfig, pwa, app, image, hooks
- Runtime Modules: @kevinmarrec/nuxt-pwa@0.0.2, @nuxt/image@1.7.0, @nuxt/content@2.12.1
- Build Modules: -
Reproduction
https://stackblitz.com/edit/github-zvae7w?file=_working.ts&view=editor
Describe the bug
In my project I use MongoDB and accordingly the library mongoose. If I now want to return my mongoose response directly in an EventHandler, the object is then of type unknown.
I was able to trace the problem back to the Serialize type of nitro:
https://github.com/unjs/nitro/blob/63526f24b03e5e5de65934c697c92dd00f1e1ab1/src/types/fetch/_serialize.ts
Through some tests I was able to determine that the mongoose object runs through the function up to line 43 (ReadonlyArray) the function NonJsonPrimitive has a negative outcome and accordingly Serialize is called recursively. The second itteration is stopped on line 37 and the type is returned on line 38 and then corresponds to unknown.
When I comment out lines 37 and 38 the type is successfully resolved and everything works as desired. Unfortunately I don't know enough about typescript to be able to estimate how the problem can be solved.
Additional context
No response
Logs
No response