useFetch loses type from /server/api after using getCachedData
Hi,
I'm using /server endpoints with Prisma ORM, which automatically share data types with the frontend, which is awesome. The problem arises when I try to use another function to cache data inside a nuxtApp instance called getCachedData. Adding this option to useFetch converts the types from the Prisma response to any type. Is there any workaround for this problem to use getCachedData and have automatic typing from the backend?
2 Replies
Well, i found solution but would be great if Nuxt can implement by self. There is available import from nitropack called { type InternalApi} that returns type from server, we can set type of returned content and now it works.
Hi @Ne0n I am facing a similar issue, where with useFetch inside a component, I am not able to get proper typings - and I also stumbled across this InternalApi type (I think it was mentioned on StackOverflow?) -> but I am still running into issues:
Can I ask you, how you used the InternalApi successfully?
IWhat I am doing is:
however Typescript then infers the "data" variable to be of type "globalThis.Ref<any>" 😦
(sorry for threadjacking! but I seem to be in the same boat as you :-D)