-
Notifications
You must be signed in to change notification settings - Fork 32
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
Type inference is not compatible with query #59
Comments
Any movement on this? @baeharam how have you worked around this issue? I'm having the same problem. |
@joeyfigaro @baeharam sorry, I completely missed this issue with a lot that's going on my personal life. I'll take a look and try to come up with a fix in the next upcoming days |
@joeyfigaro @baeharam just released v1.3.0 that exposes a new type import { TypedUseQueryOptions } from '@lukemorales/query-key-factory'
const useCustomQuery = (options?: TypedUseQueryOptions<typeof queryKey.someQuery>) => {
return useQuery({ ...options, ...queryKey.someQuery });
} As a bonus tip: since you're allowing all options (and possibly the import { TypedUseQueryOptions } from '@lukemorales/query-key-factory'
const useCustomQuery = <Data = SomeQueryResult>(options?: TypedUseQueryOptions<typeof queryKey.someQuery, Data>) => {
return useQuery({ ...options, ...queryKey.someQuery });
}
// in your component
const { data } = useCustomQuery()
// ^? SomeQueryResult
const { data } = useCustomQuery({ select: data => data.name })
// ^? string |
@lukemorales Thanks for your solution, but it has 2 limitations.
const queryKey = createQueryKeys("test", () => ({
test1Query: (params: SomeParamsType) => ({ queryKey: ..., queryFn: ... })
}); In above case, I cannot use These 2 problems are very important so I hope it could be solved ASAP. Thanks! 😄 |
@baeharam can you explain exactly why 1 is very nervous? Even with As for number 2, that's just typescript syntax: |
I can see if providing a function that returns |
@baeharam here's what I'm talking about: https://codesandbox.io/s/type-error-of-query-key-factory-forked-38yxsq?file=/src/App.tsx You can see on line 34 that typescript is complaining about the different data being returned on |
Sry, I misunderstood that original selector type inference of query. Your answer is right for number 2. But as for number 1, Reproduction: https://codesandbox.io/s/type-error-of-query-key-factory-forked-j32rwr?file=/src/App.tsx If I did something wrong, plaese tell me. Thanks! |
@baeharam your example has a small mistake on the |
@lukemorales Thanks for your quick work. It works very well 😄 But, I need this kind of utility type with |
@baeharam I can work on the |
@lukemorales Oh, I understood! Then, can you add type for |
@lukemorales I completely missed your responses here–thank you so much for the quick turnaround on this. I'm going to give the new release a shot this evening! Do you have a tip jar anywhere for your work? |
@lukemorales Thanks for your great library!
I'm using this package to manage query keys effectively, but when I have to use custom
options
to injectuseQuery
or something like this, it is not "easily" compatible with types of @tanstack/react-query.For example,
In above case, type error is occurred so I have to use specify query key type of this package.
It solves type issue, but I think is awkward to specify 3 types with
UseQueryOptions
. I want more simple solution like below.It may be related to issue #48 and #40.
I hope it could be solved elegantly :) Thanks for reading! 😄
[Reproduction]
https://codesandbox.io/s/type-error-of-query-key-factory-49so1x?file=/src/App.tsx
The text was updated successfully, but these errors were encountered: