-
-
Notifications
You must be signed in to change notification settings - Fork 1
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Library version 5.3.0
π§ Summary
Calling createQuery
with explicit generics doesn't preserve the TQueryFnData
type correctly. This results in a TypeScript type mismatch, particularly around _result
, because the function returns a type where TQueryFnData
remains unresolved.
β Expected Behavior
The returned query should have the correct TQueryFnData
, matching the one explicitly passed during the call.
β Actual Behavior
Instead of resolving TQueryFnData
to FsrsCardWithContent[]
, the returned type keeps it generic, leading to this mismatch:
Type 'Query<FsrsCardWithContent[], NetError, TQueryFnData, TQueryFnData, readonly unknown[]>' is not assignable to type 'Query<FsrsCardWithContent[], NetError, FsrsCardWithContent[], FsrsCardWithContent[], readonly unknown[]>'
π¦ Code Sample
public cacheCreateQuery<
TQueryFnData = unknown,
TError = DefaultError,
TData = TQueryFnData,
TQueryData = TQueryFnData,
TQueryKey extends QueryKey = QueryKey,
>(
queryFn: QueryFn<TQueryFnData, TError, TData, TQueryData, TQueryKey>,
params?: CreateQueryParams<TQueryFnData, TError, TData, TQueryData, TQueryKey>,
) {
return createQuery<TQueryFnData, TError, TData, TQueryData, TQueryKey>({
queryFn,
queryClient: this.queryClient,
...params,
})
}
Usage:
private readonly dueCardsQuery: Query<FsrsCardWithContent[], NetError>
this.dueCardsQuery = this.cache.createQuery<FsrsCardWithContent[], NetError>(
() => this.fsrsService.findDueByDeckId(this._deckId),
{
queryKey: this.keys.studyCards(this._deckId),
onSuccess: (data) => this._initializeStudyState(data),
onError: (error) => {
this.notify.error(error.message)
this.finishSession()
},
enableOnDemand: true,
enabled: ({ queryKey }) => typeof queryKey[1] === 'string',
},
)
π§ͺ Diagnostics
Type 'Query<FsrsCardWithContent[], NetError, TQueryFnData, TQueryFnData, readonly unknown[]>'
is not assignable to type 'Query<FsrsCardWithContent[], NetError, FsrsCardWithContent[], FsrsCardWithContent[], readonly unknown[]>'.
π Reference: Custom CacheService Implementation
You can see the full CacheService
implementation here:
π https://github.com/Tinkerbells/dolphy-frontend/blob/feat/mvc/src/common/services/cache.ts
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working