NuxtN
Nuxt2y ago
Bonteq

E2E Type safety: What am I missing?

I'm exploring e2e type safety and am curious what I am missing.

Here's my server route:

// server/api/test.ts
import type { User } from '~/types/user'

export default defineEventHandler(() => {
  return { test: '0' } as User
})


And I consume this on the client like so:

<script setup lang="ts">
import type { User } from './types/user'

const { data: userData } = await useFetch<User>('/api/test')
</script>


I have to explicitly state the expected return type from the useFetch hook. I assumed this would be inferred from the backend.

Here's a reproduction: https://github.com/CodyBontecou/nuxt-e2e-types
Was this page helpful?