i have the following code snippet:
import { get } from "lodash-es"
import {useQuery} from '@tanstack/react-query'
type QueryResult<TData extends object> =
| {
isSuccess: false
isPending: true
isError: false
data: undefined
}
| {
isSuccess: true
isPending: false
isError: false
data: TData
}
class DataListManager<TData extends object, TPath extends keyof TData> {
constructor(
private readonly _query: QueryResult<TData>,
private readonly _path: TPath,
) {}
get query() {
const items = get(this._query.data, this._path) ?? []
return {
...this._query,
data: {
items,
},
}
}
}
type Transaction = {}
function useTransactionsListManager() {
const query = useQuery({
async queryFn() {
const data = await new Promise<{transactions: Array<Transaction>}>(resolve => {
resolve({
transactions: []
})
})
return data
},
queryKey: ['transactions']
})
// Argument of type 'UseQueryResult<{ transactions: Transaction[]; }, Error>' is not assignable to parameter of type 'QueryResult<{ transactions: Transaction[]; }>'.
// Type 'QueryObserverRefetchErrorResult<{ transactions: Transaction[]; }, Error>' is not assignable to type 'QueryResult<{ transactions: Transaction[]; }>'.
// Type 'QueryObserverRefetchErrorResult<{ transactions: Transaction[]; }, Error>' is not assignable to type '{ isSuccess: true; isPending: false; isError: false; data: { transactions: Transaction[]; }; }'.
// Types of property 'isSuccess' are incompatible.
// Type 'false' is not assignable to type 'true'.ts(2345)
return new DataListManager(query, "transactions")
}
Why am I getting this error and how can I resolve it?
Update
I am unable to utilize UseQueryResult inside DataListManager due to architectural limitations.