-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[atomsWithQuery]: queryKey
type is always unknown
#25
Comments
queryKey
is not typed correctly!queryKey
is not typed correctly!
queryKey
is not typed correctly!queryKey
is not typed correctly?!
queryKey
is not typed correctly?!queryKey
type is always unknown
Nice catch. Do you know how to fix? |
I briefly looked at the source code but couldn't find the problem. But I think I can fix it. You can expect a PR today. |
Turned out that It's a Typescript bug. This works: atomsWithQuery(() => ({
queryKey: ["x", "y"],
queryFn: async ({queryKey: [x, y]}) => {
// typeof x = string
// typeof y = string
},
})) But this doesn't work because I used the atomsWithQuery((get) => ({
queryKey: ["x", "y"],
queryFn: async ({queryKey: [x, y]}) => {
// typeof x = unknown
// typeof y = unknown
},
})) It's potentioally related to this issue: microsoft/TypeScript#47599 AFAIK, there is no fix for that yet. |
The workaround is to explicitly annotate import type { Getter } from "jotai"
atomsWithQuery((get: Getter) => ({
queryKey: ["x", "y"],
queryFn: async ({queryKey: [x, y]}) => {
// typeof x = string
// typeof y = string
},
})) |
tanstack-query
infers the type ofqueryKey
parameter ofqueryFn
based on thequeryKey
option ofuseQuery
:But it's Jotai equivalent doesn't:
The text was updated successfully, but these errors were encountered: