query icon indicating copy to clipboard operation
query copied to clipboard

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

Open ap0nia opened this issue 1 year ago • 4 comments

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.

ap0nia avatar Aug 04 '24 16:08 ap0nia

☁️ Nx Cloud Report

CI is running/has finished running commands for commit d7b9a05a89bcc1fc1f1ef738ee2db5b07a9bc516. 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.

nx-cloud[bot] avatar Aug 04 '24 16:08 nx-cloud[bot]

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 d7b9a05a89bcc1fc1f1ef738ee2db5b07a9bc516:

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

codesandbox-ci[bot] avatar Aug 04 '24 16:08 codesandbox-ci[bot]

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

pkg-pr-new[bot] avatar Aug 04 '24 16:08 pkg-pr-new[bot]

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 88.27%. Comparing base (93674fe) to head (d7b9a05). :warning: Report is 1251 commits behind head on main.

:x: Your project status has failed because the head coverage (88.27%) is below the target coverage (90.00%). You can increase the head coverage or adjust the target coverage.

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%) :arrow_up:
@tanstack/svelte-query-devtools ∅ <ø> (∅)
@tanstack/svelte-query-persist-client 100.00% <ø> (ø)
@tanstack/vue-query ∅ <ø> (∅)
@tanstack/vue-query-devtools ∅ <ø> (∅)
:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Aug 04 '24 16:08 codecov[bot]

as I’m looking through stale PRs and seeing this one has conflicts, I’m gonna go ahead and close it and would like you to re-open a new PR with a type-level test that shows what this improvement does and also confirms that no existing usage will break.

thank you 🙏

TkDodo avatar Aug 19 '25 10:08 TkDodo