T
TanStack2y ago
ratty-blush

vue-query query return types are not unwraped in template?

Hello! New to vue-query so unsure if this is a user error but the return type of
const { data } = useQuery({
// ^? const data: Ref<number> | Ref<undefined>
const { data } = useQuery({
// ^? const data: Ref<number> | Ref<undefined>
is not being unwraped correcly in the <template>. vues typescript thinks I need to be calling {{ data.value}} but this is wrong and throws a runtime error, calling {{data}} in template throws a typescript error but run fine. Any ideas here?
No description
16 Replies
solid-orange
solid-orange2y ago
Which version are you using?
ratty-blush
ratty-blushOP2y ago
@M00LTi
No description
solid-orange
solid-orange2y ago
Can you do a typescript playground reproduction please
ratty-blush
ratty-blushOP2y ago
i dont think so cuz this is a vue issue on how it handles <template> with ref{} | ref<undefined> i think it needs a ref<type | undefined>
molecular-blue
molecular-blue2y ago
Isn't this just because you're not checking data is not undefined? {{ data?.name }}
ratty-blush
ratty-blushOP2y ago
No, autocompletes prompting me to do data.value.name and is not unwrapping the ref as it would any other ref. {{ data?.name }} works perfectly but throws a type error. {{ data.value?.name }} throws no type error but throws a runtime error
molecular-blue
molecular-blue2y ago
Oh very strange. This seems like a Vue TS extension issue then. Since Vue query is just returning refs you should be able to replicate this bug without Vue query. What version of the extension are you using and any other notable details you can think of
ratty-blush
ratty-blushOP2y ago
2.0.8
molecular-blue
molecular-blue2y ago
You could try messing around with these settings til you get it working hybrid mode on or off or even trying typescript nightly
No description
molecular-blue
molecular-blue2y ago
Failing that you should downgrade to the latest 1.x version and enable takeover mode It's unfortunate but the transition from v1 to v2 of this extension has been a disaster
ratty-blush
ratty-blushOP2y ago
@Sandvich no luck on any of those... Maybe im just doing something wrong here?
No description
ratty-blush
ratty-blushOP2y ago
Wraping in a computed fixes this
No description
ratty-blush
ratty-blushOP2y ago
Weirdly enough it wants me to .value even on the simple Ref like isSuccess which is Ref<false> | Ref<true> Im starting to think there is just an issue with how vue-query is typed and its not inteded to be used directly in a template?
No description
ratty-blush
ratty-blushOP2y ago
nvm this issue is showing up for useAsyncData also.... so probs a extension issue... will try fresh project and fresh vscode install.
ratty-blush
ratty-blushOP2y ago
would you look at that... working! @Sandvich thank you for the help... will try to chase this down
No description
vicious-gold
vicious-gold2y ago
in the future, please use #vue-query-questions for questions about vue-query ...

Did you find this page helpful?