Skip to content

Route.useSearch() not honouring TS types (as per the docs) #6960

@danielrhodeswarp

Description

@danielrhodeswarp

Which project does this relate to?

Router

Describe the bug

I'm absorbing and learning all things TanStack Router and TanStack start these days. Very nice! Super human and readable code - reminds me of Laravel.

Now, the following code - which is more or less verbatim from one of the Router doc pages - works under the dev server, but does not compile with npm run build and gives an error Property 'summat' does not exist on type '{}'.

Have I missed something dopey here?

Your Example Website or App

https://stackblitz.com/edit/github-kbmszfr2?file=src%2Froutes%2Fposts.index.tsx

Steps to Reproduce the Bug or Issue

Try to build a TanStack Router project with the following route file:

`
import { createFileRoute } from "@tanstack/react-router";

type SummatOptions = "summat" | "owt" | "nowt";

type SummatSearch = {
summat: SummatOptions;
};

export const Route = createFileRoute("/posts/")({
component: PostsIndexComponent,
validateSearch: (search: Record<string, unknown>): SummatSearch => {
// validate and parse the search params into a typed state
return {
summat: (search.summat as SummatOptions) || "summat",
};
},
});

function PostsIndexComponent() {
const { summat } = Route.useSearch();
return

Select a post. ?summat={summat}
;
}
`

Expected behavior

I expect, in the component function , the type of summat to be inferred and available.
Rather, it is coming out as any or {}.

Screenshots or Videos

Image

Platform

  • Router / Start Version: [1.166.6]
  • OS: [Linux]
  • Browser: [Chromium]
  • Browser Version: [145.0.7632.159]
  • Bundler: [vite]
  • Bundler Version: [e.g. 7.3.1]

Additional context

Running it in Linux but in a Docker container
(Have provided a Stackblitz but not familiar with this platform - I assume we can't npm run build in Stackblitz...)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions