Skip to content

fix(tanstack-query): exactOptionalPropertyTypes#878

Merged
dinwwwh merged 3 commits intomainfrom
fix/tanstack-query/compatible-with-exactOptionalPropertyTypes
Aug 14, 2025
Merged

fix(tanstack-query): exactOptionalPropertyTypes#878
dinwwwh merged 3 commits intomainfrom
fix/tanstack-query/compatible-with-exactOptionalPropertyTypes

Conversation

@dinwwwh
Copy link
Copy Markdown
Member

@dinwwwh dinwwwh commented Aug 14, 2025

When using "exactOptionalPropertyTypes": true in my tsconfig, I get an error saying that enabled cannot be undefined (as it is marked explicitly as undefined by ORPC, but is optional for tanstack query):

Summary by CodeRabbit

  • Refactor
    • Options objects no longer include an "enabled" field unless explicitly required (e.g., when skipping), resulting in cleaner shapes across React, Solid, Svelte, and core query utilities.
    • Type definitions updated: enabled is now optional (enabled?: boolean) in query and infinite option interfaces, improving TypeScript ergonomics without changing runtime behavior.
  • Tests
    • Assertions updated to verify the absence of the "enabled" property when not needed, aligning tests with the new option shapes.

@vercel
Copy link
Copy Markdown

vercel Bot commented Aug 14, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Project Deployment Preview Comments Updated (UTC)
orpc Ready Preview Comment Aug 14, 2025 3:09am

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Aug 14, 2025

Walkthrough

Procedure utils across query packages now include enabled: false only when input === skipToken; otherwise the enabled property is omitted. Public types are updated to make enabled optional. Tests were adjusted to assert the absence of enabled where appropriate. No other runtime/control-flow changes.

Changes

Cohort / File(s) Summary of changes
Procedure utils implementations
packages/react-query/src/procedure-utils.ts, packages/solid-query/src/procedure-utils.ts, packages/svelte-query/src/procedure-utils.ts, packages/tanstack-query/src/procedure-utils.ts
Replace enabled: condition ? false : undefined with a conditional object spread so enabled: false is included only when input === skipToken; otherwise enabled is omitted. Runtime behavior for skipToken unchanged.
Public types: enabled optional
packages/react-query/src/types.ts, packages/solid-query/src/types.ts, packages/svelte-query/src/types.ts, packages/tanstack-query/src/types.ts
Change `enabled: boolean
Tests and d.ts updates
packages/react-query/src/procedure-utils.test.ts, packages/solid-query/src/procedure-utils.test.ts, packages/svelte-query/src/procedure-utils.test.tsx, packages/tanstack-query/src/procedure-utils.test.ts, packages/tanstack-query/src/procedure-utils.test-d.ts
Update assertions to require that enabled is absent (use 'enabled' in options checks) when not using skipToken; update DTS tests to reflect enabled as optional in extended option shapes.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant ProcedureUtils
  participant QueryClient

  Caller->>ProcedureUtils: build options (includes input)
  alt input === skipToken
    ProcedureUtils-->>Caller: return { enabled: false, ...options }
  else
    ProcedureUtils-->>Caller: return { ...options } (no enabled property)
  end
  Caller->>QueryClient: call query/mutation with options
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • unnoq/orpc#840 — Prior changes to enabled handling in procedure-utils; overlaps on how enabled is emitted/typed.
  • unnoq/orpc#505 — Modifies the same option builders and skipToken-enabled behavior.
  • unnoq/orpc#516 — Adjusts streamed/live option builders; touches the same options shaping and typings.

Suggested reviewers

  • LouisHaftmann

Poem

A hop, a token, a careful little tweak,
I hide the flag when the input's not meek.
If skip comes along, false flaps its ear,
Otherwise quiet — no enabled appears.
Hooray for clean types and tests that stay clear. 🐰✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3b721b4 and d095bff.

📒 Files selected for processing (1)
  • packages/solid-query/src/types.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/solid-query/src/types.ts
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/tanstack-query/compatible-with-exactOptionalPropertyTypes

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Aug 14, 2025
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @unnoq, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a type compatibility issue related to TypeScript's "exactOptionalPropertyTypes" compiler option within the TanStack Query ecosystem. It refines how the "enabled" property is handled in query options, ensuring that it is only present when explicitly set to "false" (e.g., when using "skipToken"). This change prevents the property from being implicitly set to "undefined", which can cause type errors or unexpected behavior when "exactOptionalPropertyTypes" is enabled.

Highlights

  • Type Definition Refinement: The "enabled" property in "QueryOptionsBase" and "InfiniteOptionsBase" interfaces across various packages (React Query, Solid Query, Svelte Query, TanStack Query) has been updated from "boolean | undefined" to "?boolean", making it a truly optional property.
  • Conditional Property Inclusion: The runtime logic for constructing query options has been modified to conditionally include the "enabled: false" property only when "skipToken" is used as input. This ensures that the "enabled" property is entirely omitted when it's not explicitly "false", aligning with the updated type definitions and "exactOptionalPropertyTypes" strictness.
  • Enhanced Test Coverage: New test assertions have been added to verify that the "enabled" property is correctly omitted from query options when it's not explicitly set, confirming the intended behavior and type safety.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly addresses an issue related to TypeScript's exactOptionalPropertyTypes compiler option. The changes are consistently applied across all affected packages (react-query, solid-query, svelte-query, and tanstack-query), ensuring that optional properties are omitted rather than being assigned undefined.

The main changes include:

  • Updating type definitions from enabled: boolean | undefined to enabled?: boolean.
  • Replacing explicit undefined assignment with a conditional object spread (...condition ? { prop: value } : {}) to omit the property when not needed.
  • Updating tests to assert the absence of the property using 'enabled' in options.

The implementation is clean, correct, and thorough. I have no further suggestions. Great work!

@codecov
Copy link
Copy Markdown

codecov Bot commented Aug 14, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 8

🧹 Nitpick comments (13)
packages/tanstack-query/src/procedure-utils.test.ts (4)

49-51: Prefer own-property check over "in" and consider dropping the redundant second assertion

Using the "in" operator can match properties up the prototype chain. For stronger intent, assert against own props; the follow-up undefined check is then redundant.

-      expect('enabled' in options).toBe(false)
-      expect(options.enabled).toBeUndefined()
+      expect(Object.prototype.hasOwnProperty.call(options, 'enabled')).toBe(false)

101-103: Same as above: assert own-property absence for clarity

Align with the suggestion above to avoid prototype-chain surprises and reduce redundancy.

-      expect('enabled' in options).toBe(false)
-      expect(options.enabled).toBeUndefined()
+      expect(Object.prototype.hasOwnProperty.call(options, 'enabled')).toBe(false)

187-189: Same as above: use an own-property check for absence

Keeps tests unambiguous and consistent with exactOptionalPropertyTypes intent.

-      expect('enabled' in options).toBe(false)
-      expect(options.enabled).toBeUndefined()
+      expect(Object.prototype.hasOwnProperty.call(options, 'enabled')).toBe(false)

274-276: Same as above: own-property absence and avoid redundant undefined assertion

Small consistency/readability win across the test suite.

-      expect('enabled' in options).toBe(false)
-      expect(options.enabled).toBeUndefined()
+      expect(Object.prototype.hasOwnProperty.call(options, 'enabled')).toBe(false)
packages/svelte-query/src/procedure-utils.ts (3)

80-82: SkipToken should force-disable regardless of consumer overrides; reorder spreads (and parenthesize for clarity)

As written, a consumer could pass enabled: true and override the intended enabled: false for skipToken, causing the query to run and then throw from queryFn. If the intent is to always disable when skipToken is used, move the conditional spread after ...optionsIn so it wins.

-        ...optionsIn.input === skipToken ? { enabled: false } : {},
-        ...optionsIn,
+        ...optionsIn,
+        ...(optionsIn.input === skipToken ? { enabled: false } : {}),

If allowing consumer override is intentional, keep the current order but consider adding parentheses for readability:

-        ...optionsIn.input === skipToken ? { enabled: false } : {},
+        ...(optionsIn.input === skipToken ? { enabled: false } : {}),

104-106: Apply the same spread-ordering decision here for streamed options

Mirror the decision from .queryOptions so skipToken consistently forces disabled (or consistently allows override) across builders.

-        ...optionsIn.input === skipToken ? { enabled: false } : {},
-        ...optionsIn,
+        ...optionsIn,
+        ...(optionsIn.input === skipToken ? { enabled: false } : {}),

122-124: Apply the same spread-ordering decision here for infinite options

Ensure consistent behavior for skipToken across all option builders.

-        ...optionsIn.input === skipToken ? { enabled: false } : {},
-        ...(optionsIn as any),
+        ...(optionsIn as any),
+        ...(optionsIn.input === skipToken ? { enabled: false } : {}),
packages/svelte-query/src/procedure-utils.test.tsx (3)

36-37: Use own-property check to assert absence; optionally switch to toBeUndefined for consistency

Avoid prototype-chain surprises and keep assertions consistent across packages.

-      expect('enabled' in options).toBe(false)
-      expect(options.enabled).toBe(undefined)
+      expect(Object.prototype.hasOwnProperty.call(options, 'enabled')).toBe(false)
+      expect(options.enabled).toBeUndefined()

76-77: Same as above: prefer own-property check and consistent undefined assertion

-      expect('enabled' in options).toBe(false)
-      expect(options.enabled).toBe(undefined)
+      expect(Object.prototype.hasOwnProperty.call(options, 'enabled')).toBe(false)
+      expect(options.enabled).toBeUndefined()

135-136: Same as above: own-property absence and unified undefined assertion

-      expect('enabled' in options).toBe(false)
-      expect(options.enabled).toBe(undefined)
+      expect(Object.prototype.hasOwnProperty.call(options, 'enabled')).toBe(false)
+      expect(options.enabled).toBeUndefined()
packages/react-query/src/procedure-utils.test.ts (3)

36-37: Prefer own-property absence check; unify undefined assertion

Use an own-property check and align the undefined assertion with other packages for consistency.

-      expect('enabled' in options).toBe(false)
-      expect(options.enabled).toBe(undefined)
+      expect(Object.prototype.hasOwnProperty.call(options, 'enabled')).toBe(false)
+      expect(options.enabled).toBeUndefined()

76-77: Same as above: own-property check and unified undefined assertion

-      expect('enabled' in options).toBe(false)
-      expect(options.enabled).toBe(undefined)
+      expect(Object.prototype.hasOwnProperty.call(options, 'enabled')).toBe(false)
+      expect(options.enabled).toBeUndefined()

135-136: Same as above: own-property absence and unified undefined assertion

-      expect('enabled' in options).toBe(false)
-      expect(options.enabled).toBe(undefined)
+      expect(Object.prototype.hasOwnProperty.call(options, 'enabled')).toBe(false)
+      expect(options.enabled).toBeUndefined()
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 280152f and 3b721b4.

📒 Files selected for processing (13)
  • packages/react-query/src/procedure-utils.test.ts (3 hunks)
  • packages/react-query/src/procedure-utils.ts (3 hunks)
  • packages/react-query/src/types.ts (2 hunks)
  • packages/solid-query/src/procedure-utils.test.ts (3 hunks)
  • packages/solid-query/src/procedure-utils.ts (3 hunks)
  • packages/solid-query/src/types.ts (2 hunks)
  • packages/svelte-query/src/procedure-utils.test.tsx (3 hunks)
  • packages/svelte-query/src/procedure-utils.ts (3 hunks)
  • packages/svelte-query/src/types.ts (2 hunks)
  • packages/tanstack-query/src/procedure-utils.test-d.ts (4 hunks)
  • packages/tanstack-query/src/procedure-utils.test.ts (4 hunks)
  • packages/tanstack-query/src/procedure-utils.ts (4 hunks)
  • packages/tanstack-query/src/types.ts (2 hunks)
🔇 Additional comments (15)
packages/react-query/src/types.ts (2)

15-16: Make enabled optional: LGTM

This aligns with exactOptionalPropertyTypes and ensures the property can be omitted cleanly when not needed.


39-40: Infinite enabled optional: LGTM

Consistent with the query options shape and the PR intent to omit enabled unless necessary.

packages/solid-query/src/types.ts (2)

23-24: Optional enabled in QueryOptionsBase: LGTM

Matches the intended behavior with exactOptionalPropertyTypes.


47-48: Optional enabled in InfiniteOptionsBase: LGTM

Consistent with other packages and procedure-utils behavior.

packages/svelte-query/src/types.ts (2)

23-24: Optional enabled in QueryOptionsBase: LGTM

Correct use of optional property to avoid emitting enabled unnecessarily.


47-48: Optional enabled in InfiniteOptionsBase: LGTM

Consistent with the rest of the changes in this PR.

packages/tanstack-query/src/types.ts (2)

53-54: Optional enabled in QueryOptionsBase: LGTM

Matches procedure-utils behavior to omit enabled when not using skipToken.


78-79: Optional enabled in InfiniteOptionsBase: LGTM

Good consistency across all packages.

packages/tanstack-query/src/procedure-utils.test-d.ts (4)

151-152: Types aligned with exactOptionalPropertyTypes: enabled is optional

Changing to enabled?: boolean matches the intent to omit the property when not using skipToken. Looks good.


284-285: LGTM: streamed options enabled now optional

Consistent with the runtime behavior and tsconfig exact optional semantics.


414-415: LGTM: live options enabled now optional

Matches repo-wide change and prevents “present-but-undefined” pitfalls.


664-665: LGTM: infinite options enabled now optional

Consistent across all builders; no further action needed here.

packages/solid-query/src/procedure-utils.test.ts (3)

36-38: LGTM: Asserting absence of 'enabled' is correct with exactOptionalPropertyTypes

The new check using the in-operator precisely validates that 'enabled' is omitted when not using skipToken. The follow-up undefined check is fine as an additional guard.


76-78: LGTM: Streamed options also correctly omit 'enabled' when not using skipToken

The assertion aligns with the new semantics.


135-137: LGTM: Infinite options omit 'enabled' when not using skipToken

Consistent with the runtime behavior and types.

Comment thread packages/react-query/src/procedure-utils.ts
Comment thread packages/react-query/src/procedure-utils.ts
Comment thread packages/react-query/src/procedure-utils.ts
Comment thread packages/solid-query/src/procedure-utils.ts
Comment thread packages/solid-query/src/procedure-utils.ts
Comment thread packages/solid-query/src/procedure-utils.ts
Comment thread packages/solid-query/src/types.ts Outdated
Comment thread packages/tanstack-query/src/procedure-utils.ts
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Aug 14, 2025

More templates

@orpc/arktype

npm i https://pkg.pr.new/@orpc/arktype@878

@orpc/client

npm i https://pkg.pr.new/@orpc/client@878

@orpc/contract

npm i https://pkg.pr.new/@orpc/contract@878

@orpc/experimental-durable-event-iterator

npm i https://pkg.pr.new/@orpc/experimental-durable-event-iterator@878

@orpc/hey-api

npm i https://pkg.pr.new/@orpc/hey-api@878

@orpc/interop

npm i https://pkg.pr.new/@orpc/interop@878

@orpc/json-schema

npm i https://pkg.pr.new/@orpc/json-schema@878

@orpc/nest

npm i https://pkg.pr.new/@orpc/nest@878

@orpc/openapi

npm i https://pkg.pr.new/@orpc/openapi@878

@orpc/openapi-client

npm i https://pkg.pr.new/@orpc/openapi-client@878

@orpc/otel

npm i https://pkg.pr.new/@orpc/otel@878

@orpc/react

npm i https://pkg.pr.new/@orpc/react@878

@orpc/react-query

npm i https://pkg.pr.new/@orpc/react-query@878

@orpc/server

npm i https://pkg.pr.new/@orpc/server@878

@orpc/shared

npm i https://pkg.pr.new/@orpc/shared@878

@orpc/solid-query

npm i https://pkg.pr.new/@orpc/solid-query@878

@orpc/standard-server

npm i https://pkg.pr.new/@orpc/standard-server@878

@orpc/standard-server-aws-lambda

npm i https://pkg.pr.new/@orpc/standard-server-aws-lambda@878

@orpc/standard-server-fetch

npm i https://pkg.pr.new/@orpc/standard-server-fetch@878

@orpc/standard-server-node

npm i https://pkg.pr.new/@orpc/standard-server-node@878

@orpc/standard-server-peer

npm i https://pkg.pr.new/@orpc/standard-server-peer@878

@orpc/svelte-query

npm i https://pkg.pr.new/@orpc/svelte-query@878

@orpc/tanstack-query

npm i https://pkg.pr.new/@orpc/tanstack-query@878

@orpc/trpc

npm i https://pkg.pr.new/@orpc/trpc@878

@orpc/valibot

npm i https://pkg.pr.new/@orpc/valibot@878

@orpc/vue-colada

npm i https://pkg.pr.new/@orpc/vue-colada@878

@orpc/vue-query

npm i https://pkg.pr.new/@orpc/vue-query@878

@orpc/zod

npm i https://pkg.pr.new/@orpc/zod@878

commit: d095bff

@dinwwwh dinwwwh merged commit d53d856 into main Aug 14, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant