-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add type inference doc #6517
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
Add type inference doc #6517
Conversation
|
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. |
WalkthroughA 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 Changes
Suggested reviewers
Poem
β¨ Finishing Touches
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? πͺ§ TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
The latest updates on your projects. Learn more about Vercel for Git βοΈ
|
| // | ||
| // Infer types for a single procedure | ||
|
|
||
| import type { InferInput, InferOutput } from '@trpc/tanstack-react-query'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this exist?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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, orInferredInput
i can't motivate it but it feels wrong right now
There was a problem hiding this 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 usinginferRouterInputsandinferRouterOutputs. 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
π 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
@trpc/client
@trpc/next
@trpc/react-query
@trpc/server
@trpc/tanstack-react-query
@trpc/upgrade
commit: |
a688e7b to
1ba1f06
Compare
There was a problem hiding this 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
π 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
| inferInput, | ||
| inferOutput, |
There was a problem hiding this comment.
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
InferInputandInferOutputif these types are or might be externally consumed. - Documentation: Update the changelog to note this potentially breaking change.
|
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. |
Closes #
π― Changes
What changes are made in this PR? Is it a feature or a bug fix?
β Checklist
Summary by CodeRabbit
InferInputandInferOutputtoinferInputandinferOutputfor consistency across the codebase.