TanStackT
TanStackโ€ข2y agoโ€ข
1 reply
moderate-tomato

[TS Error] Can't export useQuery result

I'm currently getting the following TS error which I can't really resolve when trying to export a useQuery result:
The inferred type of 'query' cannot be named without a reference to '../../node_modules/@tanstack/vue-query/build/modern/useQuery-CPqkvEsh'. This is likely not portable. A type annotation is necessary.ts(2742)

Code:
import { useQuery } from "@tanstack/vue-query";

export const query = useQuery({
  queryKey: ["test"],
  queryFn: () => Promise.resolve(5),
});


The only workaround I found is to change the code the following way (But this isn't really a solution for me):
import * as VueQuery from "@tanstack/vue-query";

export const query = VueQuery.useQuery({
  queryKey: ["test"],
  queryFn: () => Promise.resolve(5),
});


A common workaround for this issue is also to set the compilerOptions.declaration option in the tsconfig.json to false. But I can't do this as I need the declaration files.

Here are also some informations I found about this error: https://github.com/microsoft/TypeScript/issues/47663#issuecomment-1519138189

Can someone help me on how to properly fix this issue or is this maybe also a bug in the library?
GitHub
Bug Report ๐Ÿ”Ž Search Terms TS2742 cannot be named without a reference ๐Ÿ•— Version & Regression Information Problems occurs with 4.5.x and 4.6.x and most likely earlier versions (I've tried a f...
"The inferred type of X cannot be named without a reference to Y" (...
Was this page helpful?