-
Notifications
You must be signed in to change notification settings - Fork 24
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
/e2e-typesafety-in-nuxt-fullstack-application.html #70
Comments
const { data: userData } = await useFetch('/api/getUser')
This is not correct. Nuxt provides type safety. The string you pass to useFetch is also a literal. '/api/getUser': {
'default': Simplify<Serialize<Awaited<ReturnType<typeof import('../../server/api/getUser').default>>>>
} If it does not work for you check if your are affected by this issue: nuxt/nuxt#23984 The preferred implementation should be to write a data fetching function or an api client and put it into useAsyncData: const { $api } = useNuxtApp()
const { data } = await useAsyncData(
'users',
$api.getUsers,
) You should use the amazing tools nuxt brings to the table. |
or write a custom useFetch like in this example: https://nuxt.com/docs/examples/advanced/use-custom-fetch-composable |
Hey @woldtwerk, thanks for the in-depth comment. I'm finally getting around to working on your suggestions and I'm curious about It's returning a type of Are you referring to the |
import { api } from './your-api.ts'
export default defineNuxtPlugin(() => ({
provide: {
api,
}
}) In your components you can access it with |
E2E Typesafety in Nuxt Fullstack Application | Cody Bontecou
Showcasing a simple approach to sharing types between the server and client within a fullstack Nuxt application.
https://www.codybontecou.com/e2e-typesafety-in-nuxt-fullstack-application.html?source=weeklyVueNews&campaign=136
The text was updated successfully, but these errors were encountered: