Typing ref for $fetch
I need to create a ref that is typed for the return value of an api endpoint. I'll be updating it from a button $fetch request. I found this site Nuxt 3 server routes and Typescript that seems to give a good way to do it via an
apiRef({ route: '/xx', method: 'get', defaultValue: null })
composable but it doesn't seem to be giving me the right typings.
For instance, I have
Result is typed as such
but userInfo is typed this way
The weird thing is the userInfo.value = result
does not give a typescript error. But trying to use {{ userInfo.username }}
gives 'username' does not exist on ...
1 Reply
I figured this out.... turns out hopping between different frameworks comes with drawbacks lol I was accidentally returning a
new Response
instead of using setResponseStatus