fix: type error when passing number to `Link.params` #5560
main fromrefs/pull/5560/head·opened fixes #5559
for some reason the type error isn't reproducible in TanStack/router repo. to check that the changes work:
- create an external repo (e.g vite tanstack router template)
- build packages with the changes
- locally install router packages
Summary by CodeRabbit#
Release Notes#
- New Features
- Routes now accept numeric values for path segments in addition to string values, improving flexibility when constructing navigation links throughout your application.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: router-core
🤖 Nx Cloud AI Fix Eligible#
To disable these notifications, a workspace admin can disable them [in workspace settings.](https://cloud.nx.app/orgs/6412ca9d1c251d000efa21ba/workspaces/6442f7de8226a6291646a813/settings#selfHealingCISettings?utm_source=pull-request&utm_medium=comment)An automatically generated fix could have helped fix failing tasks for this run, but Self-healing CI is disabled for this workspace. Visit workspace settings to enable it and get automatic fixes in future runs.
View your CI Pipeline Execution ↗ for commit e5303918c551e733e32d10e654341b1c917b59f0
Command Status Duration Result nx affected --targets=test:eslint,test:unit,tes...❌ Failed 6m 5s View ↗ nx run-many --target=build --exclude=examples/*...✅ Succeeded 1m 24s View ↗
☁️ Nx Cloud last updated this comment at
2025-10-21 02:15:04UTCMore templates
- tanstack-router-solid-example-basic
- tanstack-router-solid-example-basic-devtools-panel
- tanstack-router-solid-example-basic-file-based
- tanstack-router-solid-example-basic-non-nested-devtools
- tanstack-router-solid-example-basic-solid-query
- tanstack-router-solid-example-basic-solid-query-file-based
- tanstack-router-solid-example-basic-ssr-streaming-file-based
- tanstack-router-solid-example-kitchen-sink-file-based
- tanstack-router-solid-example-kitchen-sink-solid-query
- tanstack-router-solid-example-kitchen-sink-solid-query-file-based
- tanstack-router-solid-example-quickstart-file-based
- tanstack-solid-start-example-bare
- tanstack-solid-start-example-basic
- tanstack-solid-start-example-basic-auth
- tanstack-solid-start-example-basic-static
- tanstack-router-react-example-authenticated-routes
- tanstack-router-react-example-authenticated-routes-firebase
- tanstack-router-react-example-basic
- tanstack-router-react-example-basic-default-search-params
- tanstack-router-react-example-basic-devtools-panel
- tanstack-router-react-example-basic-file-based
- tanstack-router-react-example-basic-non-nested-devtools
- tanstack-router-react-example-react-query
- tanstack-router-react-example-basic-react-query-file-based
- tanstack-router-react-example-basic-ssr-file-based
- tanstack-router-react-example-basic-ssr-streaming-file-based
- tanstack-router-react-example-basic-virtual-file-based
- tanstack-router-react-example-basic-virtual-inside-file-based
- tanstack-router-react-example-deferred-data
- tanstack-router-i18n-paraglide
- tanstack-router-react-example-kitchen-sink
- tanstack-router-react-example-kitchen-sink-file-based
- tanstack-router-react-example-kitchen-sink-react-query
- tanstack-router-react-example-kitchen-sink-react-query-file-based
- tanstack-router-react-example-large-file-based
- tanstack-router-react-example-location-masking
- tanstack-router-react-example-navigation-blocking
- tanstack-router-react-example-quickstart
- tanstack-router-react-example-quickstart-esbuild-file-based
- tanstack-router-react-example-quickstart-file-based
- tanstack-router-react-example-quickstart-rspack-file-based
- tanstack-router-react-example-quickstart-webpack-file-based
- router-monorepo-react-query
- router-mono-simple
- router-mono-simple-lazy
- tanstack-router-react-example-scroll-restoration
- tanstack-search-validator-adapters
- tanstack-start-example-bare
- tanstack-start-example-basic
- tanstack-start-example-basic-auth
- tanstack-start-example-basic-cloudflare
- tanstack-start-example-basic-react-query
- tanstack-start-example-basic-static
- tanstack-start-bun-hosting
- tanstack-start-example-clerk-basic
- tanstack-start-example-convex-trellaux
- tanstack-start-example-counter
- tanstack-start-i18n-paraglide
- tanstack-start-example-large
- tanstack-start-example-material-ui
- tanstack-start-streaming-data-from-server-functions
- tanstack-start-example-supabase-basic
- tanstack-start-tailwind-v4
- tanstack-start-example-trellaux
- tanstack-start-example-workos
- tanstack-router-react-example-view-transitions
- tanstack-router-react-example-with-framer-motion
- tanstack-router-react-example-with-trpc
- tanstack-router-react-example-with-trpc-react-query
@tanstack/arktype-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@5560@tanstack/directive-functions-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@5560@tanstack/eslint-plugin-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@5560@tanstack/history
npm i https://pkg.pr.new/TanStack/router/@tanstack/history@5560@tanstack/nitro-v2-vite-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/nitro-v2-vite-plugin@5560@tanstack/react-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@5560@tanstack/react-router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@5560@tanstack/react-router-ssr-query
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-ssr-query@5560@tanstack/react-start
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@5560@tanstack/react-start-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@5560@tanstack/react-start-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@5560@tanstack/router-cli
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@5560@tanstack/router-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@5560@tanstack/router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@5560@tanstack/router-devtools-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@5560@tanstack/router-generator
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@5560@tanstack/router-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@5560@tanstack/router-ssr-query-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@5560@tanstack/router-utils
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@5560@tanstack/router-vite-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@5560@tanstack/server-functions-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@5560@tanstack/solid-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@5560@tanstack/solid-router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@5560@tanstack/solid-router-ssr-query
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-ssr-query@5560@tanstack/solid-start
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@5560@tanstack/solid-start-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@5560@tanstack/solid-start-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@5560@tanstack/start-client-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@5560@tanstack/start-plugin-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@5560@tanstack/start-server-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@5560@tanstack/start-static-server-functions
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-static-server-functions@5560@tanstack/start-storage-context
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@5560@tanstack/valibot-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@5560@tanstack/virtual-file-routes
npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@5560@tanstack/zod-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@5560commit:
e530391Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 997874b2919eda941944d7f47d7a2d2aac493631 and e5303918c551e733e32d10e654341b1c917b59f0.
📒 Files selected for processing (1)
packages/router-core/src/link.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Use TypeScript in strict mode with extensive type safety across the codebase
Files:
packages/router-core/src/link.ts
packages/router-core/**
📄 CodeRabbit inference engine (AGENTS.md)
Keep framework-agnostic core router logic in packages/router-core/
Files:
packages/router-core/src/link.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Test
- GitHub Check: Preview
🔇 Additional comments (1)
packages/router-core/src/link.ts (1)
577-586: Verify the fix in an external project setup.Since the issue is not reproducible within the TanStack/router repository but only in external projects, please verify that this change actually resolves the type error in a real-world setup.
As suggested in the PR description, please:
- Build the packages with these changes
- Create a minimal reproduction project (e.g., using Vite TanStack Router template)
- Install the locally built packages
- Verify that
<Link to="/$foo/bar" params={{ foo: 3 }}>no longer produces a type error
This verification is critical since the issue manifests differently in external projects versus the monorepo.
packages/router-core/src/link.ts lines 577 to 586@@ -574,4 +574,13 @@574574 in out TFrom,575575 in out TTo,576576 > {577- params: MakeRequiredParamsReducer<TRouter, 'PATH', TFrom, TTo> & {}577+ params: MakeRequiredParamsReducer<578+ TRouter,579+ 'PATH',580+ TFrom,581+ TTo582+ > extends infer Params583+ ? {584+ [K in keyof Params]: Params[K] | number585+ } & {}586+ : never⚠️ Potential issue | 🟡 Minor
Apply the same number allowance to optional path params.
The change allows numbers for required path params, but
MakeOptionalPathParams(lines 547-553) doesn't have the same allowance. If numbers are auto-stringified at runtime per the documentation, this behavior should be consistent for both required and optional path parameters.After fixing the type logic issue above, apply similar logic to
MakeOptionalPathParams:export interface MakeOptionalPathParams< in out TRouter extends AnyRouter, in out TFrom, in out TTo, > { params?: true | (ParamsReducer<TRouter, 'PATH', TFrom, TTo> extends infer Params ? Params extends true ? true : Params extends (...args: any[]) => any ? Params : { [K in keyof Params]: Params[K] | number } & {} : never) }🤖 Prompt for AI Agents
In packages/router-core/src/link.ts around lines 547-553 and 577-586, MakeOptionalPathParams currently doesn't allow numeric path param values while MakeRequiredParamsReducer does; update MakeOptionalPathParams so its mapped type also widens each param type to Params[K] | number (i.e., when resolving Params into an object map, transform each key's type to allow number in addition to the original type) and keep the existing true/functional branches intact so optional params behave consistently with required params.
⚠️ Potential issue | 🟠 Major
Fix type logic to handle
trueand function cases.The mapped type
{ [K in keyof Params]: Params[K] | number }assumesParamsis an object with parameter keys, butMakeRequiredParamsReducercan also resolve to:true(when params don't need to change between routes)- A function of type
ParamsReducerFn
When
Paramsistrue,keyof trueevaluates tonever, causing the mapped type to become{}and lose the intendedtruesemantic. WhenParamsis a function,keyof Functionincludes properties like"length","name","call", etc., creating an incorrect type.Consider this approach that explicitly handles all three cases:
- params: MakeRequiredParamsReducer< - TRouter, - 'PATH', - TFrom, - TTo - > extends infer Params - ? { - [K in keyof Params]: Params[K] | number - } & {} - : never + params: MakeRequiredParamsReducer<TRouter, 'PATH', TFrom, TTo> extends infer Params + ? Params extends true + ? true + : Params extends (...args: any[]) => any + ? Params + : { + [K in keyof Params]: Params[K] | number + } & {} + : never📝 Committable suggestion
‼️ IMPORTANT Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
params: MakeRequiredParamsReducer<TRouter, 'PATH', TFrom, TTo> extends infer Params ? Params extends true ? true : Params extends (...args: any[]) => any ? Params : { [K in keyof Params]: Params[K] | number } & {} : never🤖 Prompt for AI Agents
In packages/router-core/src/link.ts around lines 577 to 586, the current mapped type assumes Params is an object and uses {[K in keyof Params]: Params[K] | number} which breaks when MakeRequiredParamsReducer resolves to true (loses the true semantic) or to a function (pulls in function keys); change the type to a conditional that explicitly handles all three cases: if Params extends true then keep true, else if Params extends the ParamsReducerFn type then keep Params (or Params | number if numbers are valid for reducer functions per usage), else treat Params as an object and map its keys to Params[K] | number; remove the fallback to an empty intersection (& {}) and ensure the function case is excluded from key remapping by using the conditional branches.scarf005(GitHub profile, opens in a new tab) linked this to fix #5559
Sign in to join this conversation.
Walkthrough#
The TypeScript type signature for
MakeRequiredPathParamsin the Link component is updated to allow numeric values for path parameters, in addition to strings. This resolves a type mismatch where runtime code accepted numbers but the type system rejected them.Changes#
packages/router-core/src/link.tsparamsproperty type to conditionally map each parameter propertyKtoParams[K] | number, allowing both string and numeric values for path parameters in the Link component.Estimated code review effort#
🎯 2 (Simple) | ⏱️ ~5–10 minutes
The change is a straightforward TypeScript type union update affecting a single file's public API. The modification is localized to one type signature with clear intent and minimal surface area, though it does touch a public interface and should be validated against the documented behavior.
Suggested reviewers#
Poem#
Pre-merge checks and finishing touches#
✅ Passed checks (5 passed)
Link.params" directly and specifically describes the main change in the changeset. The modification to theMakeRequiredPathParamssignature is precisely addressing the TypeScript type error that prevented numeric values from being passed to path parameters, which is exactly what the title conveys. The title is concise, clear, and provides sufficient context for a reviewer scanning the history to understand the primary change without ambiguity.Link.params. The modification to theMakeRequiredPathParamssignature now allows both string and numeric values by changing theparamstype toParams[K] | number, enabling the documented behavior of auto-stringifying numbers at runtime without a type error. The change is minimal, focused, and eliminates the workaround of manually wrapping numbers inString(), aligning perfectly with the expected behavior described in the issue.packages/router-core/src/link.tsfile is modified, and specifically only theMakeRequiredPathParamssignature is updated to address the reported TypeScript type error. No extraneous files, unrelated modifications, or scope creep are present—the change is narrowly focused on resolving the specific issue of allowing numeric values in path parameters without breaking the existing runtime behavior.✨ Finishing touches
🧪 Generate unit tests (beta)
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