Skip to content

Route.useSearch() does not infer type from zod #7433

@lethib

Description

@lethib

Which project does this relate to?

Router

Describe the bug

When passing a Zod v4 schema object directly to validateSearch, TanStack Router fails to infer the search params output type. As a result, Route.useSearch() returns any, and any code that depends on the typed search params also loses type safety.

According to the documentation, there's no need to use any zodValidator object when using zod v4 : https://tanstack.com/router/latest/docs/guide/search-params#zod

The app runs well (with a Vite dev server) but the TS error is present.

Complete minimal reproducer

https://github.com/lethib/validation_issue

Steps to Reproduce the Bug

  1. Clone the minimal reproducer repo
  2. Install bun
  3. bun install inside the repo
  4. bun run typecheck at the root of the repo

Steps are also written in the minimal reproducer repo README.

Expected behavior

Normally, we getting the params from the Route.useSearch(), their type should be infer as the validator type.

Screenshots or Videos

No response

Platform

  • Router / Start Version: [e.g. 1.170.4]
  • OS: [e.g. macOS]
  • Browser: [e.g. Chrome]
  • Bundler: [e.g. vite]
  • Bundler Version: [e.g. 8.0.13]

Additional context

Claude's investigation if it helps 👇🏽

Root cause: Zod v4 declares its Standard Schema property as "~standard": ZodStandardSchemaWithJSON<this> using a polymorphic this type. When TanStack Router's ResolveValidatorOutput conditional type evaluates TValidator['~standard']['types']['output'], TypeScript cannot resolve this through an indexed access type in a generic context, so the output type collapses to any.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions