T
TanStack2y ago
extended-salmon

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
fascinating-indigo
fascinating-indigo2y ago
Which version are you using?
extended-salmon
extended-salmonOP2y ago
@M00LTi
No description
fascinating-indigo
fascinating-indigo2y ago
Can you do a typescript playground reproduction please
extended-salmon
extended-salmonOP2y 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>
conscious-sapphire
conscious-sapphire2y ago
Isn't this just because you're not checking data is not undefined? {{ data?.name }}
extended-salmon
extended-salmonOP2y 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
conscious-sapphire
conscious-sapphire2y 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
extended-salmon
extended-salmonOP2y ago
2.0.8
conscious-sapphire
conscious-sapphire2y 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
conscious-sapphire
conscious-sapphire2y 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
extended-salmon
extended-salmonOP2y ago
@Sandvich no luck on any of those... Maybe im just doing something wrong here?
No description
extended-salmon
extended-salmonOP2y ago
Wraping in a computed fixes this
No description
extended-salmon
extended-salmonOP2y 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
extended-salmon
extended-salmonOP2y ago
nvm this issue is showing up for useAsyncData also.... so probs a extension issue... will try fresh project and fresh vscode install.
extended-salmon
extended-salmonOP2y ago
would you look at that... working! @Sandvich thank you for the help... will try to chase this down
No description
flat-fuchsia
flat-fuchsia2y ago
in the future, please use #vue-query-questions for questions about vue-query ...

Did you find this page helpful?