20 Replies
id
can also be an array of strings so it may be worth asserting it is a stringI did try that as you suggested, but it didn't work so I just sent this as it was my original code
whats the updated code?
what's the file name and contents of the endpoint that this is fetching?
pages\stuff\[id]\index.vue
data is an array of elements from an explicitly typed postgresql table, it works in other routes, hell even with useFetch, just not for dynamic routes.
I mean, what is the file name of the server endpoint...
Oh sorry
server/api/v1/stuff/fetch/[id]/index.get.ts
How should it?
id
can change the output. Can you try to return result: data[0] as $yourtype?what?
How should typescript know what a function will return, if you change the input?
Example: id 1 could return a blog post, while id 2 could return nothing
That's not the issue, trust
In other non-dynamic routes it works perfectly
It has the same logic across both routes
Mostly
alright
I appreciate the constructive feedback, just hoping danielroe has something at this point 😔
@danielroe
does it work if you change to
~/server/api/v1/stuff/fetch/[id].get.ts
?No dice :/
see if you can create a reproduction then
@danielroe Created a new project and it actually seems to work. I just for the life of me cant get it to work on my actual project
Is there some sort of cache that holds types besides the
.nuxt
folder?
That would be messing with it etcYou do need to rerun nuxi dev/prepare to update types. And sometimes you might need to restart your ide
Sorry I'm bad at discord, I miss every thread
I spotted the issue and described it here: https://discord.com/channels/473401852243869706/1222581320283324446/1222581320283324446 (or is it unrelated ?)
I recently figured out that the type definition that is being passed into
result
on my part was getting malformed. Maybe an issue on another module I'm using. Simply passing the array itself instead of the object fixed my specific issue
I ran into this issue again, it seems really random so I ended up just explictly stating the type everywhere. useFetch<ResponseType>