Skip to content

Conversation

@Nick-Lucas
Copy link
Contributor

@Nick-Lucas Nick-Lucas commented Feb 18, 2025

Closes #

🎯 Changes

What changes are made in this PR? Is it a feature or a bug fix?

βœ… Checklist

  • I have followed the steps listed in the Contributing guide.
  • If necessary, I have added documentation related to the changes made.
  • I have added or updated the tests related to the changes made.

Summary by CodeRabbit

  • Documentation
    • Added a new section titled "Inferring Input and Output types" to enhance guidance on achieving type safety.
    • Included code snippets demonstrating methods for safely inferring input and output types for queries and mutations.
  • Refactor
    • Renamed types from InferInput and InferOutput to inferInput and inferOutput for consistency across the codebase.

@Nick-Lucas Nick-Lucas requested a review from a team as a code owner February 18, 2025 17:33
@railway-app
Copy link

railway-app bot commented Feb 18, 2025

This PR was not deployed automatically as @Nick-Lucas does not have access to the Railway project.

In order to get automatic PR deploys, please add @Nick-Lucas to the project inside the project settings page.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 18, 2025

Walkthrough

A new documentation section titled "Inferring Input and Output types" has been added to the TanStack React Query usage docs. This section provides guidance on inferring TypeScript types for full routers and individual procedures. It includes code examples that use both TRPC and TanStack React Query utilities for inferring input and output types, thereby aiding developers in implementing type safety in their queries and mutations. Additionally, type names have been standardized from InferInput and InferOutput to inferInput and inferOutput across various files.

Changes

File Change Summary
www/docs/client/tanstack-react-query/usage.mdx Added new section "Inferring Input and Output types" with code snippets demonstrating usage of inferRouterInputs, inferRouterOutputs, inferInput, and inferOutput for type inference.
packages/tanstack-react-query/src/index.ts Renamed exported types: InferInput to inferInput and InferOutput to inferOutput.
packages/tanstack-react-query/src/internals/createOptionsProxy.ts Renamed type aliases: InferInput to inferInput and InferOutput to inferOutput, with updated comments.
packages/tanstack-react-query/test/polymorphism.test.tsx Updated type in ExportStatus component from InferOutput<TStatus> to inferOutput<TStatus> for consistency.

Suggested reviewers

  • trpc-bot

Poem

I'm a rabbit with a bounce in my step,
Hopping through docs where new tips are kept.
Inferring types with a twitch of my ear,
Code now sings clearly, loud and clear.
With wisdom in snippets and a joyful leap,
I celebrate new docs before a carrot sleep!
πŸ°πŸ’»

✨ Finishing Touches
  • πŸ“ Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❀️ 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.
    • Generate unit testing code for this file.
    • 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. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

Documentation and Community

  • 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.

@vercel
Copy link

vercel bot commented Feb 18, 2025

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Comments Updated (UTC)
next-prisma-starter βœ… Ready (Inspect) Visit Preview Feb 18, 2025 9:38pm
og-image βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback Feb 18, 2025 9:38pm
www βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback Feb 18, 2025 9:38pm

//
// Infer types for a single procedure

import type { InferInput, InferOutput } from '@trpc/tanstack-react-query';
Copy link
Member

Choose a reason for hiding this comment

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

Does this exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I added them to support the polymorphism work for this

Copy link
Member

Choose a reason for hiding this comment

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

Why do I feel like this should either be

  • inferInput, or
  • InferredInput

i can't motivate it but it feels wrong right now

Copy link
Contributor

@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: 2

🧹 Nitpick comments (1)
www/docs/client/tanstack-react-query/usage.mdx (1)

233-241: Clarify Full Router Example
The sample code correctly shows how to infer types using inferRouterInputs and inferRouterOutputs. However, the import statement uses a placeholder path ('./path/to/server'), which might be unclear for some users. Consider adding a note or using a more realistic example to guide developers in replacing the placeholder with their actual server file path.

πŸ“œ Review details

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

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 9158020 and a688e7b.

πŸ“’ Files selected for processing (1)
  • www/docs/client/tanstack-react-query/usage.mdx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (19)
  • GitHub Check: E2E-tests (vercel-edge-runtime)
  • GitHub Check: E2E-tests (tanstack-start)
  • GitHub Check: E2E-tests (standalone-server)
  • GitHub Check: E2E-tests (soa)
  • GitHub Check: E2E-tests (next-prisma-websockets-starter)
  • GitHub Check: E2E-tests (next-prisma-todomvc)
  • GitHub Check: E2E-tests (next-prisma-starter)
  • GitHub Check: E2E-tests (next-minimal-starter)
  • GitHub Check: E2E-tests (next-formdata)
  • GitHub Check: E2E-tests (minimal-react)
  • GitHub Check: E2E-tests (fastify-server)
  • GitHub Check: E2E-tests (express-server)
  • GitHub Check: E2E-tests (express-minimal)
  • GitHub Check: E2E-tests (cloudflare-workers)
  • GitHub Check: E2E-tests (.test/ssg)
  • GitHub Check: E2E-tests (.test/internal-types-export)
  • GitHub Check: E2E-tests (.test/diagnostics-big-router)
  • GitHub Check: E2E-tests (.experimental/next-app-dir)
  • GitHub Check: test

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 18, 2025

Open in Stackblitz

@trpc/client

npm i https://pkg.pr.new/trpc/trpc/@trpc/client@6517

@trpc/next

npm i https://pkg.pr.new/trpc/trpc/@trpc/next@6517

@trpc/react-query

npm i https://pkg.pr.new/trpc/trpc/@trpc/react-query@6517

@trpc/server

npm i https://pkg.pr.new/trpc/trpc/@trpc/server@6517

@trpc/tanstack-react-query

npm i https://pkg.pr.new/trpc/trpc/@trpc/tanstack-react-query@6517

@trpc/upgrade

npm i https://pkg.pr.new/trpc/trpc/@trpc/upgrade@6517

commit: d47620b

KATT
KATT previously approved these changes Feb 18, 2025
Copy link
Contributor

@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: 1

πŸ“œ Review details

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

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between a688e7b and d47620b.

πŸ“’ Files selected for processing (4)
  • packages/tanstack-react-query/src/index.ts (1 hunks)
  • packages/tanstack-react-query/src/internals/createOptionsProxy.ts (2 hunks)
  • packages/tanstack-react-query/test/polymorphism.test.tsx (2 hunks)
  • www/docs/client/tanstack-react-query/usage.mdx (1 hunks)
βœ… Files skipped from review due to trivial changes (1)
  • packages/tanstack-react-query/src/internals/createOptionsProxy.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • www/docs/client/tanstack-react-query/usage.mdx
⏰ Context from checks skipped due to timeout of 90000ms (19)
  • GitHub Check: E2E-tests (fastify-server)
  • GitHub Check: e2e-legacy-node (next-prisma-todomvc, 20.x)
  • GitHub Check: e2e-legacy-node (next-prisma-todomvc, 18.x)
  • GitHub Check: E2E-tests (express-server)
  • GitHub Check: e2e-legacy-node (next-prisma-websockets-starter, 20.x)
  • GitHub Check: Release using pkg.pr.new
  • GitHub Check: E2E-tests (express-minimal)
  • GitHub Check: e2e-legacy-node (next-prisma-websockets-starter, 18.x)
  • GitHub Check: E2E-tests (cloudflare-workers)
  • GitHub Check: e2e-legacy-node (next-prisma-starter, 20.x)
  • GitHub Check: E2E-tests (.test/ssg)
  • GitHub Check: Test a monorepo using built declaration files
  • GitHub Check: e2e-legacy-node (next-prisma-starter, 18.x)
  • GitHub Check: E2E-tests (.test/internal-types-export)
  • GitHub Check: E2E-tests (Deno) (deno-deploy)
  • GitHub Check: E2E-tests (.test/diagnostics-big-router)
  • GitHub Check: E2E-tests (.experimental/next-app-dir)
  • GitHub Check: E2E-tests (Bun) (bun, ubuntu-latest)
  • GitHub Check: test
πŸ”‡ Additional comments (1)
packages/tanstack-react-query/test/polymorphism.test.tsx (1)

19-19: LGTM! Good test coverage.

The type import and usage have been updated correctly to use inferOutput. The test file provides comprehensive coverage of both simple and merged router scenarios, which helps validate the type changes.

Also applies to: 270-270

Comment on lines +4 to +5
inferInput,
inferOutput,
Copy link
Contributor

Choose a reason for hiding this comment

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

πŸ’‘ Verification agent

🧩 Analysis chain

Verify the impact of type renaming.

The renaming of InferInput and InferOutput to inferInput and inferOutput could be a breaking change for consumers of these types. Please ensure this change is documented in the changelog and consider adding type aliases for backward compatibility.

Run the following script to check for usages of the old type names in the codebase:


🏁 Script executed:

#!/bin/bash
# Description: Check for usages of old type names that might need updating.

# Test: Search for old type names. Expect: No occurrences of old type names.
rg -A 5 $'InferInput|InferOutput'

Length of output: 929


Ensure backward compatibility for renamed types

The renaming of InferInput and InferOutput to inferInput and inferOutput in packages/tanstack-react-query/src/index.ts has been verified against the codebase. Our search shows that the old type names still appear (e.g., in packages/server/src/vendor/standard-schema-v1/spec.ts), which means consumers relying on the uppercase versions might break. Please ensure that this change is properly documented in the changelog and consider adding type aliases in the public API that map the old type names to the new ones for backward compatibility.

  • File: packages/tanstack-react-query/src/index.ts (lines 4–5)
  • Action: Add type aliases (or deprecation warnings) for InferInput and InferOutput if these types are or might be externally consumed.
  • Documentation: Update the changelog to note this potentially breaking change.

@Nick-Lucas Nick-Lucas merged commit 47682c4 into next Feb 18, 2025
42 checks passed
@Nick-Lucas Nick-Lucas deleted the inferring-types branch February 18, 2025 21:43
@github-actions
Copy link
Contributor

This pull request has been locked because we are very unlikely to see comments on closed issues. If you think, this PR is still necessary, create a new one with the same branch. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 20, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants