TanStackT
TanStack3y ago
8 replies
skinny-azure

Wrong data type when use with Query Key Factory

Hi everyone,

I'm using React Query (React v5) + Query Key Factory + Typescript
I have created query keys with
queryFn
already, which's returning a promise of array, but when I try to get data (query.data) it's giving me an object, so my linter is complaining about it.

Codesandbox example: https://codesandbox.io/s/priceless-sara-ieo874?file=/src/App.tsx

In the example above, you can see the <List items={query.data} /> having lint error

Is there a way to get the type correctly without define it in
useQuery
, like: useQuery<MyDataType>(queries.foo()) ?
CodeSandbox
priceless-sara-ieo874 using @lukemorales/query-key-factory, loader-utils, react, react-dom, react-query, react-scripts
priceless-sara-ieo874 - CodeSandbox
Was this page helpful?