Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(query-core) Fix queries argument's type definition in queriesObserver #9449

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
yanlin-duan wants to merge 2 commits into TanStack:main
base: main
Choose a base branch
Loading
from yanlin-duan:query-core/fix-queries-type-definition

Conversation

Copy link

@yanlin-duan yanlin-duan commented Jul 17, 2025

queries argument is not typed consistently in many of the methods in queriesObserver class. The constructor typed it to be Array<QueryObserverOptions<any, any, any, any, any>> but in few other places it's Array<QueryObserverOptions> which means the default will kick in, making it Array<QueryObserverOptions<unknown, DefaultError, unknown, unknown, QueryKey>.

This caused issues when I try to interact with queryObserver:

const queryOptions: Array<QueryObserverOptions<Data, Error, SelectedData, Data, QueryKey>> = { } // some query options
// defaultedOptions typed as DefaultedQueryObserverOptions<unknown, Error, unknown, unknown, QueryKey>[]
const defaultedOptions = queryOptions.map(queryOption => {
 const defaultedOption = queryClient.defaultQueryOptions(queryOption)
 defaultedOption._optimisticResults = isRestoring
 ? 'isRestoring'
 : 'optimistic'
 return defaultedOption
})
// OK
const queriesObserver = new QueriesObserver<Array<QueryObserverResult<SelectedData, Error>>>(
 queryClient,
 defaultedOptions
)
// ERROR
// Argument of type 'DefaultedQueryObserverOptions<Data, Error, SelectedData, Data, QueryKey>[]' is not assignable to parameter of type 'QueryObserverOptions<unknown, Error, unknown, unknown, QueryKey, never>[]'.
// Type 'DefaultedQueryObserverOptions<Data, Error, SelectedData, Data, QueryKey>' is not assignable to type 'QueryObserverOptions<unknown, Error, unknown, unknown, QueryKey, never>'.
// Types of property 'enabled' are incompatible.
// Type 'Enabled<Data, Error, Data, QueryKey> | undefined' is not assignable to type 'Enabled<unknown, Error, unknown, QueryKey> | undefined'.
// Type '(query: Query<Data, Error, Data, QueryKey>) => boolean' is not assignable to type 'Enabled<unknown, Error, unknown, QueryKey> | undefined'.
// Type '(query: Query<Data, Error, Data, QueryKey>) => boolean' is not assignable to type '(query: Query<unknown, Error, unknown, QueryKey>) => boolean'.
// Types of parameters 'query' and 'query' are incompatible.
// Type 'Query<unknown, Error, unknown, QueryKey>' is not assignable to type 'Query<Data, Error, Data, QueryKey>'.
// The types of 'options.queryFn' are incompatible between these types.
// Type 'unique symbol | QueryFunction<unknown, QueryKey, never> | undefined' is not assignable to type 'unique symbol | QueryFunction<Data, QueryKey, never> | undefined'.
// Type 'QueryFunction<unknown, QueryKey, never>' is not assignable to type 'unique symbol | QueryFunction<Data, QueryKey, never> | undefined'.
// Type 'QueryFunction<unknown, QueryKey, never>' is not assignable to type 'QueryFunction<Data, QueryKey, never>'.
// Type 'unknown' is not assignable to type 'Data'.
// 'Data' could be instantiated with an arbitrary type which could be unrelated to 'unknown'.ts(2345)
queriesObserver.setQueries(defaultedOptions)

In the fix, I used the same type that the constructor takes in for queryOptions in setQueries and a few other places.

Copy link

nx-cloud bot commented Jul 30, 2025
edited
Loading

View your CI Pipeline Execution ↗ for commit 3ee21cf

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 2m 50s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 1m 21s View ↗

☁️ Nx Cloud last updated this comment at 2025年07月30日 09:58:21 UTC

Copy link

pkg-pr-new bot commented Jul 30, 2025

More templates
@tanstack/angular-query-devtools-experimental
npm i https://pkg.pr.new/@tanstack/angular-query-devtools-experimental@9449
@tanstack/angular-query-experimental
npm i https://pkg.pr.new/@tanstack/angular-query-experimental@9449
@tanstack/eslint-plugin-query
npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@9449
@tanstack/query-async-storage-persister
npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@9449
@tanstack/query-broadcast-client-experimental
npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@9449
@tanstack/query-core
npm i https://pkg.pr.new/@tanstack/query-core@9449
@tanstack/query-devtools
npm i https://pkg.pr.new/@tanstack/query-devtools@9449
@tanstack/query-persist-client-core
npm i https://pkg.pr.new/@tanstack/query-persist-client-core@9449
@tanstack/query-sync-storage-persister
npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@9449
@tanstack/react-query
npm i https://pkg.pr.new/@tanstack/react-query@9449
@tanstack/react-query-devtools
npm i https://pkg.pr.new/@tanstack/react-query-devtools@9449
@tanstack/react-query-next-experimental
npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@9449
@tanstack/react-query-persist-client
npm i https://pkg.pr.new/@tanstack/react-query-persist-client@9449
@tanstack/solid-query
npm i https://pkg.pr.new/@tanstack/solid-query@9449
@tanstack/solid-query-devtools
npm i https://pkg.pr.new/@tanstack/solid-query-devtools@9449
@tanstack/solid-query-persist-client
npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@9449
@tanstack/svelte-query
npm i https://pkg.pr.new/@tanstack/svelte-query@9449
@tanstack/svelte-query-devtools
npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@9449
@tanstack/svelte-query-persist-client
npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@9449
@tanstack/vue-query
npm i https://pkg.pr.new/@tanstack/vue-query@9449
@tanstack/vue-query-devtools
npm i https://pkg.pr.new/@tanstack/vue-query-devtools@9449

commit: 3ee21cf

Copy link
Collaborator

TkDodo commented Jul 30, 2025

why don’t we have the problem you’re describing here:

observer.setQueries(
defaultedQueries,

?

Copy link

codecov bot commented Jul 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.57%. Comparing base (cc45977) to head (3ee21cf).

Additional details and impacted files

Impacted file tree graph

@@ Coverage Diff @@
## main #9449 +/- ##
===========================================
+ Coverage 45.30% 59.57% +14.26% 
===========================================
 Files 208 137 -71 
 Lines 8283 5521 -2762 
 Branches 1872 1485 -387 
===========================================
- Hits 3753 3289 -464 
+ Misses 4085 1930 -2155 
+ Partials 445 302 -143 
Components Coverage Δ
@tanstack/angular-query-devtools-experimental ∅ <ø> (∅)
@tanstack/angular-query-experimental 85.00% <ø> (ø)
@tanstack/eslint-plugin-query ∅ <ø> (∅)
@tanstack/query-async-storage-persister 43.85% <ø> (ø)
@tanstack/query-broadcast-client-experimental 24.39% <ø> (ø)
@tanstack/query-codemods ∅ <ø> (∅)
@tanstack/query-core 97.69% <ø> (ø)
@tanstack/query-devtools 3.55% <ø> (ø)
@tanstack/query-persist-client-core 79.47% <ø> (ø)
@tanstack/query-sync-storage-persister 84.61% <ø> (ø)
@tanstack/query-test-utils ∅ <ø> (∅)
@tanstack/react-query 95.95% <ø> (ø)
@tanstack/react-query-devtools 10.00% <ø> (ø)
@tanstack/react-query-next-experimental ∅ <ø> (∅)
@tanstack/react-query-persist-client 100.00% <ø> (ø)
@tanstack/solid-query 78.13% <ø> (ø)
@tanstack/solid-query-devtools ∅ <ø> (∅)
@tanstack/solid-query-persist-client 100.00% <ø> (ø)
@tanstack/svelte-query 87.58% <ø> (ø)
@tanstack/svelte-query-devtools ∅ <ø> (∅)
@tanstack/svelte-query-persist-client 100.00% <ø> (ø)
@tanstack/vue-query 71.10% <ø> (ø)
@tanstack/vue-query-devtools ∅ <ø> (∅)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /