How to use UseSuspenseQueryResult type #6574
Answered
by
TkDodo
nilshartmann
asked this question in
Q&A
-
Hi all, I'm wondering, why this code snippet do not raise a typescript error, even async function doFetch() {
return "happy holidays ☃️"
}
function useGetBestWishesQuery(): UseSuspenseQueryResult<number> {
return useSuspenseQuery({
queryKey: ["..."],
queryFn: () => doFetch(),
});
} Only if I add a type parameter to (Query v5.14.2, TypeScript 5.2.2) Thanks for any hints! |
Beta Was this translation helpful? Give feedback.
Answered by
TkDodo
Dec 22, 2023
Replies: 1 comment 2 replies
-
hm, weird. the same issue for It actually also behaves the same way back to v3 Maybe file an issue but my recommendation is to use type inference and not annotate the result of |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
nilshartmann
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hm, weird. the same issue for
useQuery
.https://www.typescriptlang.org/play?#code/ATCWFsAcHsCcBdgG9gFcDOBTAiqzsBPAGmAFUtd8CAlTdVAG0QF9gAzWacYAcgAF4AQwB26IQGMA1gHpYmQePgBaAI55CPAFAhtwQegLDx7VEfihow4ABNoAMUzxxACwAUASmS6Qc+KlhWAETOgpCQBMDO0Ayg1oIE6MCAwGSA8H+Busy6umymihZWGJgA4o4AQnTwAOqg6M50lIQeAFxkFOo0dIzwADzCqOAARvgAfF4gPo7+BW1Urkje42pUANKYBC0A2oEAdLuBALpECyBLhHbCLR7AALyjtg5Obu5H48DM7gDcGZq64pZiyBsgiEbxuaCwJXg5TE1Vq9XaHl00mkrxAAD0APxAA
It actually also behaves the same way back to v3
Maybe file an issue but my recommendation is to use type inference and not annotate the result of
useQuery