Skip to content

Link to property type signature does not support number/delta usage #13164

@sean-perkins

Description

@sean-perkins

I'm using React Router as a...

library

Reproduction

  1. Go to https://stackblitz.com/edit/github-sedw5gxm?file=app%2Froutes%2Fhome.tsx
  2. Click "Click me"
  3. Observe: Navigation back occurs correctly
  4. Re-open https://stackblitz.com/edit/github-sedw5gxm?file=app%2Froutes%2Fhome.tsx or navigate forward
  5. Open home.tsx
  6. Observe: The manual type cast to the to property
  7. Remove the type cast
  8. Observe: Type error for the to property

System Info

System:
    OS: macOS 15.1
    CPU: (12) arm64 Apple M4 Pro
    Memory: 151.52 MB / 24.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.13.1 - ~/.volta/tools/image/node/22.13.1/bin/node
    npm: 10.9.2 - ~/.volta/tools/image/node/22.13.1/bin/npm
    pnpm: 9.15.0 - ~/.volta/bin/pnpm
    bun: 1.1.38 - /opt/homebrew/bin/bun
  Browsers:
    Chrome: 133.0.6943.142
    Safari: 18.1
  npmPackages:
    @react-router/dev: ^7.1.1 => 7.1.3 
    @react-router/node: ^7.1.1 => 7.1.3 
    @react-router/serve: ^7.1.1 => 7.1.3 
    react-router: ^7.1.1 => 7.1.3 
    vite: catalog: => 6.0.11

Used Package Manager

pnpm

Expected Behavior

Developers can assign a number to the to property of Link to do delta navigation.

<Link to={-1}>Click me</Link>

Actual Behavior

The Link component only supports a string type for the to property, while being built around the history API that supports the delta usage.

The runtime behavior is correct with this usage:

<Link to={-1 as unknown as string}>Click me</Link

however developers shouldn't need to cast around the restrictive types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions