Skip to content
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

fix(svelte-query): specify readonly on create-queries options #7848

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ap0nia
Copy link
Contributor

@ap0nia ap0nia commented Aug 4, 2024

The queries property in the first argument provided to createQueries should have the readonly modifier.

Minimum Reproduction

import { createQueries, type QueriesOptions } from '@tanstack/svelte-query'

const a = [] as readonly QueriesOptions<any>[]

// @ts-expect-error type readonly any[] is not assignable...
createQueries({ queries: a })

Expectation

A readonly QueriesOptions<any>[] and variations of this type should be compatible with the createQueries function signature.

Context

I'm writing a utility function that generates strongly typed query options, which will be plugged into createQueries directly. It looks something like this:

function createTypedQueryOptions<T>(options: T): readonly [...QueriesOptions<T>] {}

The main points being that the function is generic, and returns a readonly tuple with strongly typed query options that are derived from the input generic. However, the readonly modifier is currently not compatible when using createQueries because the queries property is missing it...

Other APIs

This is based on the types exported from react-query's useQueries, as well as solid-query's createQueries.

Copy link

nx-cloud bot commented Aug 4, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit d7b9a05. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 2 targets

Sent with 💌 from NxCloud.

Copy link

codesandbox-ci bot commented Aug 4, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit d7b9a05:

Sandbox Source
@tanstack/query-example-angular-basic Configuration
@tanstack/query-example-react-basic-typescript Configuration
@tanstack/query-example-solid-basic-typescript Configuration
@tanstack/query-example-svelte-basic Configuration
@tanstack/query-example-vue-basic Configuration

Copy link

pkg-pr-new bot commented Aug 4, 2024

commit: d7b9a05

pnpm add https://pkg.pr.new/@tanstack/angular-query-devtools-experimental@7848
pnpm add https://pkg.pr.new/@tanstack/angular-query-experimental@7848
pnpm add https://pkg.pr.new/@tanstack/eslint-plugin-query@7848
pnpm add https://pkg.pr.new/@tanstack/query-async-storage-persister@7848
pnpm add https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@7848
pnpm add https://pkg.pr.new/@tanstack/query-core@7848
pnpm add https://pkg.pr.new/@tanstack/query-devtools@7848
pnpm add https://pkg.pr.new/@tanstack/query-persist-client-core@7848
pnpm add https://pkg.pr.new/@tanstack/query-sync-storage-persister@7848
pnpm add https://pkg.pr.new/@tanstack/react-query@7848
pnpm add https://pkg.pr.new/@tanstack/react-query-devtools@7848
pnpm add https://pkg.pr.new/@tanstack/react-query-next-experimental@7848
pnpm add https://pkg.pr.new/@tanstack/react-query-persist-client@7848
pnpm add https://pkg.pr.new/@tanstack/solid-query@7848
pnpm add https://pkg.pr.new/@tanstack/solid-query-devtools@7848
pnpm add https://pkg.pr.new/@tanstack/solid-query-persist-client@7848
pnpm add https://pkg.pr.new/@tanstack/svelte-query@7848
pnpm add https://pkg.pr.new/@tanstack/svelte-query-devtools@7848
pnpm add https://pkg.pr.new/@tanstack/svelte-query-persist-client@7848
pnpm add https://pkg.pr.new/@tanstack/vue-query@7848
pnpm add https://pkg.pr.new/@tanstack/vue-query-devtools@7848

Open in Stackblitz

More templates

Copy link

codecov bot commented Aug 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.27%. Comparing base (93674fe) to head (d7b9a05).
Report is 347 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #7848       +/-   ##
===========================================
+ Coverage   41.42%   88.27%   +46.84%     
===========================================
  Files         184       18      -166     
  Lines        7331      162     -7169     
  Branches     1531       32     -1499     
===========================================
- Hits         3037      143     -2894     
+ Misses       3889       16     -3873     
+ Partials      405        3      -402     
Components Coverage Δ
@tanstack/angular-query-devtools-experimental ∅ <ø> (∅)
@tanstack/angular-query-experimental ∅ <ø> (∅)
@tanstack/eslint-plugin-query ∅ <ø> (∅)
@tanstack/query-async-storage-persister ∅ <ø> (∅)
@tanstack/query-broadcast-client-experimental ∅ <ø> (∅)
@tanstack/query-codemods ∅ <ø> (∅)
@tanstack/query-core ∅ <ø> (∅)
@tanstack/query-devtools ∅ <ø> (∅)
@tanstack/query-persist-client-core ∅ <ø> (∅)
@tanstack/query-sync-storage-persister ∅ <ø> (∅)
@tanstack/react-query ∅ <ø> (∅)
@tanstack/react-query-devtools ∅ <ø> (∅)
@tanstack/react-query-next-experimental ∅ <ø> (∅)
@tanstack/react-query-persist-client ∅ <ø> (∅)
@tanstack/solid-query ∅ <ø> (∅)
@tanstack/solid-query-devtools ∅ <ø> (∅)
@tanstack/solid-query-persist-client ∅ <ø> (∅)
@tanstack/svelte-query 87.33% <ø> (+24.64%) ⬆️
@tanstack/svelte-query-devtools ∅ <ø> (∅)
@tanstack/svelte-query-persist-client 100.00% <ø> (ø)
@tanstack/vue-query ∅ <ø> (∅)
@tanstack/vue-query-devtools ∅ <ø> (∅)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant