You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think your best bet to avoid TS complaints but maintain type-safety is to also give your variable a type to give TS a clue that the query key is a tuple not an array. Like this.
Agree with @rabengraph.
Or you can create a query key factory that manages the query keys, which also handle type nicely. There's a good blog article from @TkDodo
Describe the bug
Given: Values for
UseQueryOptions
are assigned to a variable. The variable is not explicitly typed.When passing this variable to
useQuery()
a type error is thrown.In contrast, when passing the values to
useQuery()
inline, the same values are accepted anduseQuery()
infers the types properly.Your minimal, reproducible example
https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAbzgRQK4FMoE8BiqB2AxjMBPgMJkzoAeMANHKgM7pqZZwC+cAZlBBBwA5FHQBDYgFoAjhmzCAsACgVhMs3i90MQgAsAyoJ17g+AOZwAvHHHMsROAAoEKuO7hyOAaXRYAXHAA2ki8EBDcALr0KlyB7Nh4RCRklPjUdAA8bh5BOR4ersoFJR5hEIH4qCAARpj5JVwxxR6RKgB8AJTW7XAACgIgwKwAdGLMEAA2AG7oLnA14lCB5dydKiq0kLB8BMSk+EysABLhANZO3UUNAPQ3cGaTZui2UObV6OnMgQDu0GfMBosNjyLDzLyJfArHT6IwgExmcyMCFYXwBYKhcKBACMUTWGxa7jucDAdmYcGmS2A4hqkxedle73h6UCABMIOhyfgIPA-lAAXAGup8JpPKCAIJvck2JAonBQvgwwzGGCmCzI0FowIhPhYuC4riRbhA1gJMEoyXmZjrVTKLgqIA
Steps to reproduce
Look at line 20 in the
typescriptlang.org/play
example.Expected behavior
Given: Values for UseQueryOptions are assigned to a variable. The variable is not explicitly typed.
When passing this variable to
useQuery()
,How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
https://www.typescriptlang.org/play
react-query version
3.39.1
TypeScript version
4.7.2
Additional context
No response
The text was updated successfully, but these errors were encountered: