TanStackT
TanStack13mo ago
3 replies
brilliant-lime

Wrapper around injectQuery

Has anyone been able to create a wrapper around injectQuery?
I want to extend the query so that it has some more methods.
Doing a simple shallow copy of the query works well:
const q = injectQuery(optionsFn)
const extendedQuery = {
  ...q,
}

if (extendedQuery.isSuccess()) {
  extendedQuery.data() // T
}

But as soon as I add a simple method, the type predicates just seems to be broken:
const qs = injectQuery(optionsFn)
const extendedQuery = {
  ...q,
  test: () => true
}

if (extendedQuery.isSuccess()) {
  extendedQuery.data() // T | undefined
}
Was this page helpful?