Skip to content

NitroRoute Serialize Type #2583

@Ayax0

Description

@Ayax0

Environment


  • Operating System: Windows_NT
  • Node Version: v20.9.0
  • Nitro Version: 2.9.6
  • Package Manager: npm@10.1.0

Reproduction

https://stackblitz.com/edit/github-7q39gn?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/v2/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

nuxt/nuxt#27968

Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions