So, I am using a selector-esque with react-query and I am getting an error when I try to pluck some values off of the cache.
Here is the error I am getting: TS2339: Property 'phone' does not exist on type 'QueryObserverResult '.
- Whats the "type" of select here?
here is the cache mutation:
export default function useProductCache (select: ?): QueryObserverResult<Product, Error> {
const queryClient = useQueryClient();
return useQuery(
queryKey,
async () => {
const product = await queryClient.getQueryData(queryKey);
return product;
},
{ select }
);
}
And here is where I create the "selector-esque" function:
export const useProductByKeysSelector = (keys: string[]) => useProductCache((data: Product) => {
const objectByKeys = keys.reduce<Record<string, any>>((byKeys, k) => {
byKeys[k] = get(data, k);
return byKeys;
}, {})
return objectByKeys;
})
So, "phone" IS on Product. But its still giving me an error (as noted above)?
What if I wanted to "add" a custom key in the return, how would I type that?