framework icon indicating copy to clipboard operation
framework copied to clipboard

Bad typing with useFetch and Nuxt API with prisma include

Open aspitrine opened this issue 2 years ago • 3 comments

Environment

Nuxi 3.0.0-rc.12 17:03:11 RootDir: /Users/quentinlogie/dev/nuxt-app 17:03:11 Nuxt project info: (copied to clipboard) 17:03:11


  • Operating System: Darwin
  • Node Version: v16.17.1
  • Nuxt Version: 3.0.0-rc.12
  • Nitro Version: 0.6.0
  • Package Manager: [email protected]
  • Builder: vite
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

Link to the project https://github.com/aspitrine/nuxt-api-bad-typing

Describe the bug

I use prisma to get data from my database and get typed data.

The type between the API and my useFetch was not the same (missing posts types)

// /pages/index.vue
const {data: users} = useFetch('/api/hello')
// type of users => const users: Ref<User[]>
// /server/api/hello.ts
const users = await prisma.user.findMany({
    include: {
      posts: true
    }
  })
  return users
// types of users 
// const users: (User & {
//    posts: Post[];
// })[]

Additional context

No response

Logs

No response

aspitrine avatar Nov 03 '22 16:11 aspitrine