openapi-ts icon indicating copy to clipboard operation
openapi-ts copied to clipboard

Improved types for Vue Tanstack Query

Open rkorzhoff opened this issue 1 year ago • 1 comments

Description

It would be great if you could improve the types for requests parameters, especially considering Vue 3 refs. It’s a common use case to pass reactive variables as parameters

image

Reproducible example or configuration

https://stackblitz.com/edit/vitejs-vite-cwmyp5

Just install deps and run npm run ts:check

OpenAPI specification (optional)

No response

System information (optional)

No response

rkorzhoff avatar Sep 09 '24 18:09 rkorzhoff

Actually, MaybeRefOrGetter<T> should be used and toValue(value) can be used to resolve this.

holtgrewe avatar Nov 04 '24 11:11 holtgrewe

I can confirm this feature is really important. Actually it is near impossible for me to use tanstack plugin cuz almost every param is ref/computed.

zumm avatar Jan 09 '25 13:01 zumm

@zumm Hi, aware of this pain! Planning to tackle this after releasing the Nuxt client as it touches on those concepts as well

mrlubos avatar Jan 09 '25 14:01 mrlubos

I wanna share workaround i found recently. useQuery (and others vue-query composables) accepts reactive objects as options. So you can do things like that:

const somethingId = ref(23)
const query = useQuery(computed(() => getSomethingByIdOptions({ path: { id: somethingId.value } })))

Still a bit clunky, but makes it possible to use generated by tanstack plugin code.

zumm avatar Feb 02 '25 11:02 zumm

Thanks @zumm! The Nuxt client is now available so this should get prioritised soon

mrlubos avatar Feb 02 '25 11:02 mrlubos

@mrlubos As always, I'm grateful for the work you put into this wonderful library.

Is there any timeline regarding a fix to this?

holtgrewe avatar Feb 21 '25 19:02 holtgrewe

Hey, this is super important.

h-sigma avatar Mar 21 '25 11:03 h-sigma