Skip to content

Path parameters for server routes are not parsed correctly and have invalid typescript types #8431

Description

@valerii15298

Which project does this relate to?

Router

Describe the bug

Path parameters for server routes are not parsed correctly and have invalid typescript types.
https://github.com/valerii15298/tss-repros/blob/server-route-path-params-parsing/src/routes/%24id.tsx

Reproduction code:

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

export const Route = createFileRoute("/$id")({
  params: {
    parse: (p) => ({ id: Number(p.id) }),
    stringify: (p) => ({ id: String(p.id) }),
  },
  server: {
    handlers: {
      GET({ params }) {
        // params type: { id: number; } but in runtime actually { id: string; }
        console.log(typeof params.id)
        return Response.json(params);
      },
    },
  },
});

Complete minimal reproducer

https://github.com/valerii15298/tss-repros/tree/server-route-path-params-parsing

Steps to Reproduce the Bug

Go to the reproduction repo branch, run pnpm dev and go to http://localhost:3000/44 in browser.
id parameter is actually a string while shows as number type

Expected behavior

Path parameters should be parsed for server routes too or the types should be correct.

Screenshots or Videos

No response

Platform

@tanstack/react-router@1.170.36
@tanstack/react-start@1.168.53

Additional context

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions