Skip to content

fix: parse params union inference#7306

Merged
schiller-manuel merged 1 commit intomainfrom
fix-parse-params-type
May 1, 2026
Merged

fix: parse params union inference#7306
schiller-manuel merged 1 commit intomainfrom
fix-parse-params-type

Conversation

@schiller-manuel
Copy link
Copy Markdown
Contributor

@schiller-manuel schiller-manuel commented Apr 30, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Corrected type inference for params.parse with discriminated-union path parameters to properly resolve the expected type shape.
    • Enhanced type validation to catch errors when required path parameters are missing from parsing results.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 30, 2026

📝 Walkthrough

Walkthrough

Type inference improvements for the params.parse function in routes with discriminated-union path parameters. The ParseParamsFn type is simplified and a new ValidateParsedParams validation type enforces that parsed params match the route's resolved shape. Includes test cases and release documentation.

Changes

Cohort / File(s) Summary
Route Parameter Type Validation
packages/router-core/src/route.ts
Simplifies ParseParamsFn return type to TParams | false. Adds ValidateParsedParams type validation applied to both params.parse and deprecated parseParams properties, enforcing type compatibility and preventing incompatible param transformations.
Type Tests
packages/react-router/tests/fileRoute.test-d.tsx
Introduces attachmentRoute test file route with discriminated-union params.parse transformation. Adds TypeScript module augmentation for route metadata and validation tests confirming correct type inference and error detection on dropped required params.
Release Documentation
.changeset/fix-parse-params-union.md
Documents patch release fixing params.parse type inference for discriminated-union path parameters while maintaining existing path key validation behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A hop through types, so crisp and clear,
Where unions parse both far and near,
The validate guard now keeps us true,
No wayward params slip right through!
Param paths purified

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: parse params union inference' directly and clearly describes the main change: fixing type inference for params.parse with discriminated-union path parameters.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-parse-params-type

Review rate limit: 4/5 reviews remaining, refill in 12 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud
Copy link
Copy Markdown
Contributor

nx-cloud Bot commented Apr 30, 2026

View your CI Pipeline Execution ↗ for commit 7de1159

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ✅ Succeeded 7m 53s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 2m 1s View ↗

☁️ Nx Cloud last updated this comment at 2026-05-01 00:02:45 UTC

@github-actions
Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

1 package(s) bumped directly, 22 bumped as dependents.

🟩 Patch bumps

Package Version Reason
@tanstack/router-core 1.169.0 → 1.169.1 Changeset
@tanstack/react-router 1.169.0 → 1.169.1 Dependent
@tanstack/react-start 1.167.56 → 1.167.57 Dependent
@tanstack/react-start-client 1.166.46 → 1.166.47 Dependent
@tanstack/react-start-rsc 0.0.35 → 0.0.36 Dependent
@tanstack/react-start-server 1.166.47 → 1.166.48 Dependent
@tanstack/router-cli 1.166.39 → 1.166.40 Dependent
@tanstack/router-generator 1.166.38 → 1.166.39 Dependent
@tanstack/router-plugin 1.167.30 → 1.167.31 Dependent
@tanstack/router-vite-plugin 1.166.45 → 1.166.46 Dependent
@tanstack/solid-router 1.169.0 → 1.169.1 Dependent
@tanstack/solid-start 1.167.53 → 1.167.54 Dependent
@tanstack/solid-start-client 1.166.45 → 1.166.46 Dependent
@tanstack/solid-start-server 1.166.46 → 1.166.47 Dependent
@tanstack/start-client-core 1.168.0 → 1.168.1 Dependent
@tanstack/start-plugin-core 1.169.11 → 1.169.12 Dependent
@tanstack/start-server-core 1.167.25 → 1.167.26 Dependent
@tanstack/start-static-server-functions 1.166.39 → 1.166.40 Dependent
@tanstack/start-storage-context 1.166.33 → 1.166.34 Dependent
@tanstack/vue-router 1.169.0 → 1.169.1 Dependent
@tanstack/vue-start 1.167.49 → 1.167.50 Dependent
@tanstack/vue-start-client 1.166.41 → 1.166.42 Dependent
@tanstack/vue-start-server 1.166.42 → 1.166.43 Dependent

@github-actions
Copy link
Copy Markdown
Contributor

Bundle Size Benchmarks

  • Commit: e31f7aad4906
  • Measured at: 2026-04-30T23:56:06.403Z
  • Baseline source: history:82b06132af77
  • Dashboard: bundle-size history
Scenario Current (gzip) Delta vs baseline Raw Brotli Trend
react-router.minimal 87.15 KiB 0 B (0.00%) 273.94 KiB 75.70 KiB ██▇▇▇▇▇▁▁▁▁
react-router.full 90.68 KiB 0 B (0.00%) 285.45 KiB 78.71 KiB ▇▇█████▁▁▁▁
solid-router.minimal 35.38 KiB 0 B (0.00%) 106.25 KiB 31.81 KiB ██▇▇▇▇▇▁▁▁▁
solid-router.full 40.10 KiB 0 B (0.00%) 120.46 KiB 36.04 KiB ██▇▇▇▇▇▁▁▁▁
vue-router.minimal 53.15 KiB 0 B (0.00%) 151.39 KiB 47.73 KiB ███████▁▁▁▁
vue-router.full 58.28 KiB 0 B (0.00%) 167.56 KiB 52.18 KiB ███████▁▁▁▁
react-start.minimal 101.76 KiB 0 B (0.00%) 322.10 KiB 87.97 KiB ███████▁▁▁▁
react-start.full 105.19 KiB 0 B (0.00%) 332.43 KiB 90.96 KiB ███████▁▁▁▁
react-start.rsbuild.minimal 99.33 KiB 0 B (0.00%) 316.47 KiB 85.46 KiB █████▂▂▁▁▁▁
react-start.rsbuild.full 102.63 KiB 0 B (0.00%) 326.90 KiB 88.28 KiB █████▂▂▁▁▁▁
solid-start.minimal 49.40 KiB 0 B (0.00%) 152.08 KiB 43.60 KiB ██▇▇▇▇▇▁▁▁▁
solid-start.full 55.20 KiB 0 B (0.00%) 168.98 KiB 48.51 KiB ██▇▇▇▇▇▁▁▁▁

Trend sparkline is historical gzip bytes ending with this PR measurement; lower is better.

Copy link
Copy Markdown
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.

🧹 Nitpick comments (1)
packages/react-router/tests/fileRoute.test-d.tsx (1)

155-162: ⚡ Quick win

Add a matching negative test for deprecated parseParams too.

route.ts now enforces the same validation on parseParams, but this file currently guards only params.parse.

💡 Proposed test addition
 test('when file route params.parse drops a path param', () => {
   createFileRoute('/invoices/$invoiceId')({
     params: {
       // `@ts-expect-error` parsed params must keep path param keys
       parse: () => ({}),
     },
   })
 })
+
+test('when deprecated parseParams drops a path param', () => {
+  createFileRoute('/invoices/$invoiceId')({
+    // `@ts-expect-error` parsed params must keep path param keys
+    parseParams: () => ({}),
+  })
+})
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/react-router/tests/fileRoute.test-d.tsx` around lines 155 - 162, Add
a matching negative test that mirrors the existing "when file route params.parse
drops a path param" case but targets the deprecated params.parseParams API: call
createFileRoute('/invoices/$invoiceId') with params: { /* `@ts-expect-error`
parsed params must keep path param keys */ parseParams: () => ({}) } and assert
TypeScript emits the expected error; reference the same test harness and test
name pattern (e.g., "when file route params.parseParams drops a path param") and
reuse createFileRoute to locate where to add the test.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/react-router/tests/fileRoute.test-d.tsx`:
- Around line 155-162: Add a matching negative test that mirrors the existing
"when file route params.parse drops a path param" case but targets the
deprecated params.parseParams API: call createFileRoute('/invoices/$invoiceId')
with params: { /* `@ts-expect-error` parsed params must keep path param keys */
parseParams: () => ({}) } and assert TypeScript emits the expected error;
reference the same test harness and test name pattern (e.g., "when file route
params.parseParams drops a path param") and reuse createFileRoute to locate
where to add the test.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 85d23201-6b08-4a21-9225-fa8d6a60bf7c

📥 Commits

Reviewing files that changed from the base of the PR and between e31f7aa and 7de1159.

📒 Files selected for processing (3)
  • .changeset/fix-parse-params-union.md
  • packages/react-router/tests/fileRoute.test-d.tsx
  • packages/router-core/src/route.ts

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 30, 2026

More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/@tanstack/arktype-adapter@7306

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/@tanstack/eslint-plugin-router@7306

@tanstack/eslint-plugin-start

npm i https://pkg.pr.new/@tanstack/eslint-plugin-start@7306

@tanstack/history

npm i https://pkg.pr.new/@tanstack/history@7306

@tanstack/nitro-v2-vite-plugin

npm i https://pkg.pr.new/@tanstack/nitro-v2-vite-plugin@7306

@tanstack/react-router

npm i https://pkg.pr.new/@tanstack/react-router@7306

@tanstack/react-router-devtools

npm i https://pkg.pr.new/@tanstack/react-router-devtools@7306

@tanstack/react-router-ssr-query

npm i https://pkg.pr.new/@tanstack/react-router-ssr-query@7306

@tanstack/react-start

npm i https://pkg.pr.new/@tanstack/react-start@7306

@tanstack/react-start-client

npm i https://pkg.pr.new/@tanstack/react-start-client@7306

@tanstack/react-start-rsc

npm i https://pkg.pr.new/@tanstack/react-start-rsc@7306

@tanstack/react-start-server

npm i https://pkg.pr.new/@tanstack/react-start-server@7306

@tanstack/router-cli

npm i https://pkg.pr.new/@tanstack/router-cli@7306

@tanstack/router-core

npm i https://pkg.pr.new/@tanstack/router-core@7306

@tanstack/router-devtools

npm i https://pkg.pr.new/@tanstack/router-devtools@7306

@tanstack/router-devtools-core

npm i https://pkg.pr.new/@tanstack/router-devtools-core@7306

@tanstack/router-generator

npm i https://pkg.pr.new/@tanstack/router-generator@7306

@tanstack/router-plugin

npm i https://pkg.pr.new/@tanstack/router-plugin@7306

@tanstack/router-ssr-query-core

npm i https://pkg.pr.new/@tanstack/router-ssr-query-core@7306

@tanstack/router-utils

npm i https://pkg.pr.new/@tanstack/router-utils@7306

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/@tanstack/router-vite-plugin@7306

@tanstack/solid-router

npm i https://pkg.pr.new/@tanstack/solid-router@7306

@tanstack/solid-router-devtools

npm i https://pkg.pr.new/@tanstack/solid-router-devtools@7306

@tanstack/solid-router-ssr-query

npm i https://pkg.pr.new/@tanstack/solid-router-ssr-query@7306

@tanstack/solid-start

npm i https://pkg.pr.new/@tanstack/solid-start@7306

@tanstack/solid-start-client

npm i https://pkg.pr.new/@tanstack/solid-start-client@7306

@tanstack/solid-start-server

npm i https://pkg.pr.new/@tanstack/solid-start-server@7306

@tanstack/start-client-core

npm i https://pkg.pr.new/@tanstack/start-client-core@7306

@tanstack/start-fn-stubs

npm i https://pkg.pr.new/@tanstack/start-fn-stubs@7306

@tanstack/start-plugin-core

npm i https://pkg.pr.new/@tanstack/start-plugin-core@7306

@tanstack/start-server-core

npm i https://pkg.pr.new/@tanstack/start-server-core@7306

@tanstack/start-static-server-functions

npm i https://pkg.pr.new/@tanstack/start-static-server-functions@7306

@tanstack/start-storage-context

npm i https://pkg.pr.new/@tanstack/start-storage-context@7306

@tanstack/valibot-adapter

npm i https://pkg.pr.new/@tanstack/valibot-adapter@7306

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/@tanstack/virtual-file-routes@7306

@tanstack/vue-router

npm i https://pkg.pr.new/@tanstack/vue-router@7306

@tanstack/vue-router-devtools

npm i https://pkg.pr.new/@tanstack/vue-router-devtools@7306

@tanstack/vue-router-ssr-query

npm i https://pkg.pr.new/@tanstack/vue-router-ssr-query@7306

@tanstack/vue-start

npm i https://pkg.pr.new/@tanstack/vue-start@7306

@tanstack/vue-start-client

npm i https://pkg.pr.new/@tanstack/vue-start-client@7306

@tanstack/vue-start-server

npm i https://pkg.pr.new/@tanstack/vue-start-server@7306

@tanstack/zod-adapter

npm i https://pkg.pr.new/@tanstack/zod-adapter@7306

commit: 7de1159

@schiller-manuel schiller-manuel merged commit 4a1e63f into main May 1, 2026
16 checks passed
@schiller-manuel schiller-manuel deleted the fix-parse-params-type branch May 1, 2026 00:04
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 1, 2026

Merging this PR will not alter performance

✅ 5 untouched benchmarks
⏩ 1 skipped benchmark1


Comparing fix-parse-params-type (7de1159) with main (82b0613)2

Open in CodSpeed

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports.

  2. No successful run was found on main (e31f7aa) during the generation of this report, so 82b0613 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

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