Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type inference and code execution interrupted by undocumented SerializeObject #1138

Open
tamutus opened this issue Apr 14, 2023 · 3 comments
Labels

Comments

@tamutus
Copy link

tamutus commented Apr 14, 2023

Environment


  • Operating System: Windows_NT
  • Node Version: v18.15.0
  • Nuxt Version: 3.3.2
  • Nitro Version: 2.3.2
  • Package Manager: npm@9.6.2
  • Builder: vite
  • User Config: modules, app, components, routeRules, runtimeConfig
  • Runtime Modules: @nuxtjs/google-fonts@3.0.0
  • Build Modules: -

Reproduction

Somebody over in Nuxt issues made this, though the issue was closed in the Nuxt forum and explicitly deferred to Nitro, though I don't see a respective issue here (sorry if I missed it). Essentially, people including me are confused about how to exchange data from API to frontend because a mysterious SerializeObject type is wrapped around it. What will and won't be converted to this? how do we undo this or otherwise process this?

https://stackblitz.com/edit/github-xbwzpm?file=server%2Fapi%2Ftest.ts

Describe the bug

Specifically: When I write an API event handler that returns an array of a prisma type, and consume that type with the nuxt useFetch composable in the frontend, it's wrapped in SerializeObject<CorrectType[]>, and typescript says this backend data is unassignable to a variable of the type that was sent.

Additional context

Here's the Intellisense that is generated in VS Code
image

image

image

image

Logs

No response

Copy link
Member

This is documented somewhat here, if you're using Nuxt.

Otherwise you can read #1002. This should end up converting types to valid JSON (which is what gets output anyway). If it's not working (ie. stripping valid types) then please do provide a reproduction. 🙏

Copy link
Contributor

@tamutus As this is not a bug, maybe you can turn this issue into a feature request to achieve what you want?

@mubaidr
Copy link

mubaidr commented Nov 23, 2023

Looking for support for alternative serializer, this would avoid re-writing/ updates types where date is involved. Especially where types are auto-generated, like Prisma.

Right now, every type on front end has to be wrapped with Serialize from nitropack to match returned data type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants