Skip to content

Conversation

leesb971204
Copy link
Contributor

@leesb971204 leesb971204 commented Oct 2, 2025

fixes #5203

Summary by CodeRabbit

  • Refactor
    • Updated navigation API typings to include a default destination when none is specified, improving TypeScript inference and reducing the need for explicit generics. This results in fewer editor warnings and a smoother development experience. Existing code continues to work without changes.
  • Chores
    • Internal type cleanup only; no runtime or user-facing behavior changes.

Signed-off-by: leesb971204 <leesb971204@gmail.com>
Copy link
Contributor

coderabbitai bot commented Oct 2, 2025

Walkthrough

Updated the generic parameter of UseNavigateResult in packages/router-core/src/useNavigate.ts by adding a default value '.' to TTo, changing its declaration from TTo extends string | undefined to TTo extends string | undefined = '.'.

Changes

Cohort / File(s) Summary
Router core typing update
packages/router-core/src/useNavigate.ts
Added default generic '.' for TTo in UseNavigateResult (TTo extends string | undefined = '.'), affecting type inference when TTo is omitted.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I nudge the types, a hop, a dot—
A path implied, yet not forgot.
With ears alert to generics’ tune,
I set defaults by afternoon.
Now navigate, my friend, with glee—
The carrot points to “.” for me. 🥕🐇

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Linked Issues Check ⚠️ Warning The pull request only introduces a default generic parameter for TTo in UseNavigateResult and does not modify the type of the search option in NavigateOptions or inline navigate calls as required by issue #5203, so it fails to address the linked issue’s objective. The type definitions for the search option in NavigateOptions and the inline navigate signature need to be updated to accept updater functions without errors, ensuring consistency with issue #5203.
Out of Scope Changes Check ⚠️ Warning The change introduces a default generic parameter for TTo in UseNavigateResult which is unrelated to correcting the search option type in useNavigate as described in the linked issue, making it an out-of-scope modification. The PR should remove or separate the TTo default change and instead implement the necessary type adjustments to the NavigateOptions search property to resolve issue #5203.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly specifies the main change by indicating that a default value for the TTo generic parameter was added to the UseNavigateResult type in router-core, matching the code modifications.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 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 4b0004c and 25fac7e.

📒 Files selected for processing (1)
  • packages/router-core/src/useNavigate.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/useNavigate.ts
packages/router-core/**

📄 CodeRabbit inference engine (AGENTS.md)

Keep framework-agnostic core router logic in packages/router-core/

Files:

  • packages/router-core/src/useNavigate.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/useNavigate.ts (1)

6-6: Align useNavigate’s TTo default with core NavigateOptions.
The default TTo = '.' now matches the existing pattern in NavigateOptions, restoring inference for inline navigate({ search: … }) without breaking existing usages. Ensure your test suite covers the search callback scenario from issue #5203.


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

Copy link

nx-cloud bot commented Oct 2, 2025

View your CI Pipeline Execution ↗ for commit 25fac7e

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

☁️ Nx Cloud last updated this comment at 2025-10-02 01:39:20 UTC

Copy link

pkg-pr-new bot commented Oct 2, 2025

More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@5337

@tanstack/directive-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@5337

@tanstack/eslint-plugin-router

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

@tanstack/history

npm i https://pkg.pr.new/TanStack/router/@tanstack/history@5337

@tanstack/nitro-v2-vite-plugin

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

@tanstack/react-router

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

@tanstack/react-router-devtools

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

@tanstack/react-router-ssr-query

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

@tanstack/react-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@5337

@tanstack/react-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@5337

@tanstack/react-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@5337

@tanstack/router-cli

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

@tanstack/router-core

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

@tanstack/router-devtools

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

@tanstack/router-devtools-core

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

@tanstack/router-generator

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

@tanstack/router-plugin

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

@tanstack/router-ssr-query-core

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

@tanstack/router-utils

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

@tanstack/router-vite-plugin

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

@tanstack/server-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@5337

@tanstack/solid-router

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

@tanstack/solid-router-devtools

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

@tanstack/solid-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@5337

@tanstack/solid-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@5337

@tanstack/solid-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@5337

@tanstack/start-client-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@5337

@tanstack/start-plugin-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@5337

@tanstack/start-server-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@5337

@tanstack/start-static-server-functions

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

@tanstack/start-storage-context

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@5337

@tanstack/valibot-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@5337

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@5337

@tanstack/zod-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@5337

commit: 25fac7e

export type UseNavigateResult<TDefaultFrom extends string> = <
TRouter extends RegisteredRouter,
TTo extends string | undefined,
TTo extends string | undefined = '.',
Copy link
Contributor Author

@leesb971204 leesb971204 Oct 2, 2025

Choose a reason for hiding this comment

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

The reason the code shown in the issue is inferred as never is because the to value is missing.

If navigateOptions.to is not set, it will navigate to current route from here.

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.

The type of the "search" option in useNavigate is incorrect.
1 participant